@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
@@ -39,6 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.createFc3Operations = void 0;
40
40
  const fc = __importStar(require("@alicloud/fc20230330"));
41
41
  const node_fs_1 = __importDefault(require("node:fs"));
42
+ const polling_1 = require("../polling");
43
+ const constants_1 = require("../constants");
42
44
  const buildCodeLocation = (codePath, ossCode) => {
43
45
  if (ossCode) {
44
46
  return new fc.InputCodeLocation({
@@ -50,224 +52,496 @@ const buildCodeLocation = (codePath, ossCode) => {
50
52
  const codeBase64 = codeBuffer.toString('base64');
51
53
  return new fc.InputCodeLocation({ zipFile: codeBase64 });
52
54
  };
53
- /* istanbul ignore next */ const createFc3Operations = (fc3Client) => ({
54
- createFunction: async (config, codePath, ossCode) => {
55
- const createFunctionInput = new fc.CreateFunctionInput({
56
- functionName: config.functionName,
57
- runtime: config.runtime,
58
- handler: config.handler,
59
- memorySize: config.memorySize,
60
- timeout: config.timeout,
61
- code: buildCodeLocation(codePath, ossCode),
62
- ...(config.diskSize && { diskSize: config.diskSize }),
63
- ...(config.environmentVariables && { environmentVariables: config.environmentVariables }),
64
- ...(config.gpuConfig && {
65
- gpuConfig: new fc.GPUConfig({
66
- gpuMemorySize: config.gpuConfig.gpuMemorySize,
67
- gpuType: config.gpuConfig.gpuType,
55
+ /* istanbul ignore next */ const createFc3Operations = (fc3Client) => {
56
+ const operations = {
57
+ waitForFunctionActive: async (functionName) => {
58
+ try {
59
+ return await (0, polling_1.pollUntil)({
60
+ description: `FC3 function ${functionName} to become Active`,
61
+ fetch: () => operations.getFunction(functionName),
62
+ isDone: (info) => {
63
+ if (info?.state === 'Failed') {
64
+ throw new Error(`FC3 function ${functionName} is in Failed state (reason: ${info.stateReason ?? 'unknown'})`);
65
+ }
66
+ return info?.state === 'Active';
67
+ },
68
+ intervalMs: constants_1.SCF_STATUS_POLL_INTERVAL_MS,
69
+ maxAttempts: constants_1.SCF_STATUS_POLL_MAX_ATTEMPTS,
70
+ });
71
+ }
72
+ catch (e) {
73
+ if (e instanceof polling_1.PollingTimeoutError) {
74
+ throw new Error(`Timed out waiting for FC3 function ${functionName} to become Active`, {
75
+ cause: e,
76
+ });
77
+ }
78
+ throw e;
79
+ }
80
+ },
81
+ waitForFunctionDeleted: async (functionName) => {
82
+ try {
83
+ await (0, polling_1.pollUntil)({
84
+ description: `FC3 function ${functionName} to be deleted`,
85
+ fetch: () => operations.getFunction(functionName),
86
+ isDone: (info) => info === null,
87
+ intervalMs: constants_1.SCF_STATUS_POLL_INTERVAL_MS,
88
+ maxAttempts: constants_1.SCF_STATUS_POLL_MAX_ATTEMPTS,
89
+ });
90
+ }
91
+ catch (e) {
92
+ if (e instanceof polling_1.PollingTimeoutError) {
93
+ throw new Error(`Timed out waiting for FC3 function ${functionName} to be deleted`, {
94
+ cause: e,
95
+ });
96
+ }
97
+ throw e;
98
+ }
99
+ },
100
+ createFunction: async (config, codePath, ossCode) => {
101
+ const createFunctionInput = new fc.CreateFunctionInput({
102
+ functionName: config.functionName,
103
+ runtime: config.runtime,
104
+ handler: config.handler,
105
+ memorySize: config.memorySize,
106
+ timeout: config.timeout,
107
+ code: buildCodeLocation(codePath, ossCode),
108
+ ...(config.diskSize && { diskSize: config.diskSize }),
109
+ ...(config.environmentVariables && { environmentVariables: config.environmentVariables }),
110
+ ...(config.gpuConfig && {
111
+ gpuConfig: new fc.GPUConfig({
112
+ gpuMemorySize: config.gpuConfig.gpuMemorySize,
113
+ gpuType: config.gpuConfig.gpuType,
114
+ }),
115
+ }),
116
+ ...(config.vpcConfig && {
117
+ vpcConfig: new fc.VPCConfig({
118
+ vpcId: config.vpcConfig.vpcId,
119
+ vSwitchIds: config.vpcConfig.vSwitchIds,
120
+ securityGroupId: config.vpcConfig.securityGroupId,
121
+ }),
68
122
  }),
69
- }),
70
- ...(config.vpcConfig && {
71
- vpcConfig: new fc.VPCConfig({
72
- vpcId: config.vpcConfig.vpcId,
73
- vSwitchIds: config.vpcConfig.vSwitchIds,
74
- securityGroupId: config.vpcConfig.securityGroupId,
123
+ ...(config.nasConfig && {
124
+ nasConfig: new fc.NASConfig({
125
+ userId: config.nasConfig.userId,
126
+ groupId: config.nasConfig.groupId,
127
+ mountPoints: config.nasConfig.mountPoints?.map((mp) => new fc.NASMountConfig({
128
+ serverAddr: mp.serverAddr,
129
+ mountDir: mp.mountDir,
130
+ enableTLS: mp.enableTls,
131
+ })),
132
+ }),
75
133
  }),
76
- }),
77
- ...(config.nasConfig && {
78
- nasConfig: new fc.NASConfig({
79
- userId: config.nasConfig.userId,
80
- groupId: config.nasConfig.groupId,
81
- mountPoints: config.nasConfig.mountPoints?.map((mp) => new fc.NASMountConfig({
82
- serverAddr: mp.serverAddr,
83
- mountDir: mp.mountDir,
84
- enableTLS: mp.enableTls,
85
- })),
134
+ ...(config.logConfig && {
135
+ logConfig: new fc.LogConfig({
136
+ project: config.logConfig.project,
137
+ logstore: config.logConfig.logstore,
138
+ enableRequestMetrics: config.logConfig.enableRequestMetrics,
139
+ enableInstanceMetrics: config.logConfig.enableInstanceMetrics,
140
+ logBeginRule: config.logConfig.logBeginRule,
141
+ }),
86
142
  }),
87
- }),
88
- ...(config.logConfig && {
89
- logConfig: new fc.LogConfig({
90
- project: config.logConfig.project,
91
- logstore: config.logConfig.logstore,
92
- enableRequestMetrics: config.logConfig.enableRequestMetrics,
93
- enableInstanceMetrics: config.logConfig.enableInstanceMetrics,
94
- logBeginRule: config.logConfig.logBeginRule,
143
+ ...(config.customContainerConfig && {
144
+ customContainerConfig: new fc.CustomContainerConfig({
145
+ image: config.customContainerConfig.image,
146
+ entrypoint: config.customContainerConfig.entrypoint,
147
+ command: config.customContainerConfig.command,
148
+ port: config.customContainerConfig.port,
149
+ accelerationType: config.customContainerConfig.accelerationType,
150
+ }),
95
151
  }),
96
- }),
97
- ...(config.customContainerConfig && {
98
- customContainerConfig: new fc.CustomContainerConfig({
99
- image: config.customContainerConfig.image,
100
- entrypoint: config.customContainerConfig.entrypoint,
101
- command: config.customContainerConfig.command,
102
- port: config.customContainerConfig.port,
103
- accelerationType: config.customContainerConfig.accelerationType,
152
+ ...(config.description && { description: config.description }),
153
+ ...(config.internetAccess !== undefined && { internetAccess: config.internetAccess }),
154
+ ...(config.role && { role: config.role }),
155
+ ...(config.tags && {
156
+ tags: config.tags.map((t) => new fc.Tag({ key: t.key, value: t.value })),
104
157
  }),
105
- }),
106
- ...(config.description && { description: config.description }),
107
- ...(config.internetAccess !== undefined && { internetAccess: config.internetAccess }),
108
- ...(config.role && { role: config.role }),
109
- });
110
- const request = new fc.CreateFunctionRequest({
111
- body: createFunctionInput,
112
- });
113
- await fc3Client.createFunction(request);
114
- },
115
- getFunction: async (functionName) => {
116
- try {
117
- const request = new fc.GetFunctionRequest({});
118
- const response = await fc3Client.getFunction(functionName, request);
119
- if (!response || !response.body) {
120
- return null;
158
+ });
159
+ const request = new fc.CreateFunctionRequest({
160
+ body: createFunctionInput,
161
+ });
162
+ await fc3Client.createFunction(request);
163
+ // CreateFunction is async on Aliyun FC3 — the function stays in 'Creating'
164
+ // until the platform finishes provisioning. Follow-up calls (e.g.
165
+ // createTrigger) fail if issued too early, so poll until Active before
166
+ // returning.
167
+ await operations.waitForFunctionActive(config.functionName);
168
+ },
169
+ getFunction: async (functionName) => {
170
+ try {
171
+ const request = new fc.GetFunctionRequest({});
172
+ const response = await fc3Client.getFunction(functionName, request);
173
+ if (!response || !response.body) {
174
+ return null;
175
+ }
176
+ const body = response.body;
177
+ return {
178
+ functionName: body.functionName,
179
+ functionArn: body.functionArn,
180
+ functionId: body.functionId,
181
+ runtime: body.runtime,
182
+ handler: body.handler,
183
+ memorySize: body.memorySize,
184
+ timeout: body.timeout,
185
+ diskSize: body.diskSize,
186
+ cpu: body.cpu,
187
+ environmentVariables: body.environmentVariables,
188
+ vpcConfig: body.vpcConfig
189
+ ? {
190
+ vpcId: body.vpcConfig.vpcId,
191
+ vSwitchIds: body.vpcConfig.vSwitchIds,
192
+ securityGroupId: body.vpcConfig.securityGroupId,
193
+ role: body.vpcConfig.role,
194
+ }
195
+ : undefined,
196
+ gpuConfig: body.gpuConfig
197
+ ? {
198
+ gpuMemorySize: body.gpuConfig.gpuMemorySize,
199
+ gpuType: body.gpuConfig.gpuType,
200
+ }
201
+ : undefined,
202
+ nasConfig: body.nasConfig
203
+ ? {
204
+ userId: body.nasConfig.userId,
205
+ groupId: body.nasConfig.groupId,
206
+ mountPoints: body.nasConfig.mountPoints?.map((mp) => ({
207
+ serverAddr: mp.serverAddr,
208
+ mountDir: mp.mountDir,
209
+ enableTls: mp.enableTLS,
210
+ })),
211
+ }
212
+ : undefined,
213
+ logConfig: body.logConfig
214
+ ? {
215
+ project: body.logConfig.project,
216
+ logstore: body.logConfig.logstore,
217
+ enableRequestMetrics: body.logConfig.enableRequestMetrics,
218
+ enableInstanceMetrics: body.logConfig.enableInstanceMetrics,
219
+ enableLlmMetrics: body.logConfig.enableLlmMetrics,
220
+ logBeginRule: body.logConfig.logBeginRule,
221
+ }
222
+ : undefined,
223
+ customContainerConfig: body.customContainerConfig
224
+ ? {
225
+ image: body.customContainerConfig.image,
226
+ entrypoint: body.customContainerConfig.entrypoint,
227
+ command: body.customContainerConfig.command,
228
+ port: body.customContainerConfig.port,
229
+ accelerationType: body.customContainerConfig.accelerationType,
230
+ accelerationInfo: body.customContainerConfig.accelerationInfo
231
+ ? { status: body.customContainerConfig.accelerationInfo.status }
232
+ : undefined,
233
+ acrInstanceId: body.customContainerConfig.acrInstanceId,
234
+ healthCheckConfig: body.customContainerConfig.healthCheckConfig
235
+ ? {
236
+ failureThreshold: body.customContainerConfig.healthCheckConfig.failureThreshold,
237
+ httpGetUrl: body.customContainerConfig.healthCheckConfig.httpGetUrl,
238
+ initialDelaySeconds: body.customContainerConfig.healthCheckConfig.initialDelaySeconds,
239
+ periodSeconds: body.customContainerConfig.healthCheckConfig.periodSeconds,
240
+ successThreshold: body.customContainerConfig.healthCheckConfig.successThreshold,
241
+ timeoutSeconds: body.customContainerConfig.healthCheckConfig.timeoutSeconds,
242
+ }
243
+ : undefined,
244
+ registryConfig: body.customContainerConfig.registryConfig
245
+ ? {
246
+ authConfig: body.customContainerConfig.registryConfig.authConfig
247
+ ? {
248
+ password: body.customContainerConfig.registryConfig.authConfig.password,
249
+ userName: body.customContainerConfig.registryConfig.authConfig.userName,
250
+ }
251
+ : undefined,
252
+ }
253
+ : undefined,
254
+ resolvedImageUri: body.customContainerConfig.resolvedImageUri,
255
+ }
256
+ : undefined,
257
+ description: body.description,
258
+ internetAccess: body.internetAccess,
259
+ role: body.role,
260
+ codeChecksum: body.codeChecksum,
261
+ codeSize: body.codeSize,
262
+ createdTime: body.createdTime,
263
+ lastModifiedTime: body.lastModifiedTime,
264
+ state: body.state,
265
+ stateReason: body.stateReason,
266
+ stateReasonCode: body.stateReasonCode,
267
+ lastUpdateStatus: body.lastUpdateStatus,
268
+ lastUpdateStatusReason: body.lastUpdateStatusReason,
269
+ lastUpdateStatusReasonCode: body.lastUpdateStatusReasonCode,
270
+ tags: body.tags?.map((t) => ({ Key: t.key, Value: t.value })),
271
+ // Maximum-detail fields — retain everything GetFunction returns so
272
+ // state keeps full resource detail (runtime config, concurrency,
273
+ // lifecycle hooks, storage mounts, network/DNS, tracing, layers).
274
+ customDNS: body.customDNS
275
+ ? {
276
+ nameServers: body.customDNS.nameServers,
277
+ searches: body.customDNS.searches,
278
+ dnsOptions: body.customDNS.dnsOptions?.map((o) => ({
279
+ name: o.name,
280
+ value: o.value,
281
+ })),
282
+ }
283
+ : undefined,
284
+ customRuntimeConfig: body.customRuntimeConfig
285
+ ? {
286
+ args: body.customRuntimeConfig.args,
287
+ command: body.customRuntimeConfig.command,
288
+ port: body.customRuntimeConfig.port,
289
+ healthCheckConfig: body.customRuntimeConfig.healthCheckConfig
290
+ ? {
291
+ failureThreshold: body.customRuntimeConfig.healthCheckConfig.failureThreshold,
292
+ httpGetUrl: body.customRuntimeConfig.healthCheckConfig.httpGetUrl,
293
+ initialDelaySeconds: body.customRuntimeConfig.healthCheckConfig.initialDelaySeconds,
294
+ periodSeconds: body.customRuntimeConfig.healthCheckConfig.periodSeconds,
295
+ successThreshold: body.customRuntimeConfig.healthCheckConfig.successThreshold,
296
+ timeoutSeconds: body.customRuntimeConfig.healthCheckConfig.timeoutSeconds,
297
+ }
298
+ : undefined,
299
+ }
300
+ : undefined,
301
+ disableInjectCredentials: body.disableInjectCredentials,
302
+ disableOndemand: body.disableOndemand,
303
+ enableLongLiving: body.enableLongLiving,
304
+ idleTimeout: body.idleTimeout,
305
+ instanceConcurrency: body.instanceConcurrency,
306
+ instanceIsolationMode: body.instanceIsolationMode,
307
+ instanceLifecycleConfig: body.instanceLifecycleConfig
308
+ ? {
309
+ initializer: body.instanceLifecycleConfig.initializer
310
+ ? {
311
+ handler: body.instanceLifecycleConfig.initializer.handler,
312
+ timeout: body.instanceLifecycleConfig.initializer.timeout,
313
+ command: body.instanceLifecycleConfig.initializer.command,
314
+ }
315
+ : undefined,
316
+ preStop: body.instanceLifecycleConfig.preStop
317
+ ? {
318
+ handler: body.instanceLifecycleConfig.preStop.handler,
319
+ timeout: body.instanceLifecycleConfig.preStop.timeout,
320
+ command: body.instanceLifecycleConfig.preStop.command,
321
+ }
322
+ : undefined,
323
+ }
324
+ : undefined,
325
+ invocationRestriction: body.invocationRestriction
326
+ ? {
327
+ disable: body.invocationRestriction.disable,
328
+ lastModifiedTime: body.invocationRestriction.lastModifiedTime,
329
+ reason: body.invocationRestriction.reason,
330
+ }
331
+ : undefined,
332
+ juiceFsConfig: body.juiceFsConfig
333
+ ? {
334
+ envs: body.juiceFsConfig.envs,
335
+ mountPoints: body.juiceFsConfig.mountPoints?.map((m) => ({
336
+ args: m.args,
337
+ mountDir: m.mountDir,
338
+ remoteDir: m.remoteDir,
339
+ token: m.token,
340
+ volumeName: m.volumeName,
341
+ })),
342
+ }
343
+ : undefined,
344
+ layers: body.layers?.map((l) => ({ arn: l.arn, size: l.size })),
345
+ lockInfo: body.lockInfo
346
+ ? {
347
+ lockedAt: body.lockInfo.lockedAt,
348
+ lockedBy: body.lockInfo.lockedBy,
349
+ lockedResources: body.lockInfo.lockedResources,
350
+ }
351
+ : undefined,
352
+ microSandboxConfig: body.microSandboxConfig
353
+ ? {
354
+ osType: body.microSandboxConfig.osType,
355
+ readyCommand: body.microSandboxConfig.readyCommand,
356
+ startCommand: body.microSandboxConfig.startCommand,
357
+ }
358
+ : undefined,
359
+ ossMountConfig: body.ossMountConfig
360
+ ? {
361
+ mountPoints: body.ossMountConfig.mountPoints?.map((m) => ({
362
+ bucketName: m.bucketName,
363
+ bucketPath: m.bucketPath,
364
+ endpoint: m.endpoint,
365
+ mountDir: m.mountDir,
366
+ readOnly: m.readOnly,
367
+ })),
368
+ }
369
+ : undefined,
370
+ polarFsConfig: body.polarFsConfig
371
+ ? {
372
+ groupId: body.polarFsConfig.groupId,
373
+ userId: body.polarFsConfig.userId,
374
+ mountPoints: body.polarFsConfig.mountPoints?.map((m) => ({
375
+ instanceId: m.instanceId,
376
+ mountDir: m.mountDir,
377
+ readOnly: m.readOnly,
378
+ remoteDir: m.remoteDir,
379
+ })),
380
+ }
381
+ : undefined,
382
+ resourceGroupId: body.resourceGroupId,
383
+ sessionAffinity: body.sessionAffinity,
384
+ sessionAffinityConfig: body.sessionAffinityConfig,
385
+ tracingConfig: body.tracingConfig
386
+ ? {
387
+ type: body.tracingConfig.type,
388
+ params: body.tracingConfig.params,
389
+ }
390
+ : undefined,
391
+ };
392
+ }
393
+ catch (error) {
394
+ if (error &&
395
+ typeof error === 'object' &&
396
+ 'code' in error &&
397
+ error.code === 'FunctionNotFound') {
398
+ return null;
399
+ }
400
+ throw error;
121
401
  }
122
- const body = response.body;
123
- return {
124
- functionName: body.functionName,
125
- functionArn: body.functionArn,
126
- functionId: body.functionId,
127
- runtime: body.runtime,
128
- handler: body.handler,
129
- memorySize: body.memorySize,
130
- timeout: body.timeout,
131
- diskSize: body.diskSize,
132
- cpu: body.cpu,
133
- environmentVariables: body.environmentVariables,
134
- vpcConfig: body.vpcConfig
135
- ? {
136
- vpcId: body.vpcConfig.vpcId,
137
- vSwitchIds: body.vpcConfig.vSwitchIds,
138
- securityGroupId: body.vpcConfig.securityGroupId,
139
- }
140
- : undefined,
141
- gpuConfig: body.gpuConfig
142
- ? {
143
- gpuMemorySize: body.gpuConfig.gpuMemorySize,
144
- gpuType: body.gpuConfig.gpuType,
145
- }
146
- : undefined,
147
- nasConfig: body.nasConfig
148
- ? {
149
- userId: body.nasConfig.userId,
150
- groupId: body.nasConfig.groupId,
151
- mountPoints: body.nasConfig.mountPoints?.map((mp) => ({
402
+ },
403
+ updateFunctionConfiguration: async (config) => {
404
+ const updateFunctionInput = new fc.UpdateFunctionInput({
405
+ runtime: config.runtime,
406
+ handler: config.handler,
407
+ memorySize: config.memorySize,
408
+ timeout: config.timeout,
409
+ ...(config.diskSize && { diskSize: config.diskSize }),
410
+ ...(config.environmentVariables && { environmentVariables: config.environmentVariables }),
411
+ ...(config.gpuConfig && {
412
+ gpuConfig: new fc.GPUConfig({
413
+ gpuMemorySize: config.gpuConfig.gpuMemorySize,
414
+ gpuType: config.gpuConfig.gpuType,
415
+ }),
416
+ }),
417
+ ...(config.vpcConfig && {
418
+ vpcConfig: new fc.VPCConfig({
419
+ vpcId: config.vpcConfig.vpcId,
420
+ vSwitchIds: config.vpcConfig.vSwitchIds,
421
+ securityGroupId: config.vpcConfig.securityGroupId,
422
+ }),
423
+ }),
424
+ ...(config.nasConfig && {
425
+ nasConfig: new fc.NASConfig({
426
+ userId: config.nasConfig.userId,
427
+ groupId: config.nasConfig.groupId,
428
+ mountPoints: config.nasConfig.mountPoints?.map((mp) => new fc.NASMountConfig({
152
429
  serverAddr: mp.serverAddr,
153
430
  mountDir: mp.mountDir,
154
- enableTls: mp.enableTLS,
431
+ enableTLS: mp.enableTls,
155
432
  })),
156
- }
157
- : undefined,
158
- logConfig: body.logConfig
159
- ? {
160
- project: body.logConfig.project,
161
- logstore: body.logConfig.logstore,
162
- enableRequestMetrics: body.logConfig.enableRequestMetrics,
163
- enableInstanceMetrics: body.logConfig.enableInstanceMetrics,
164
- logBeginRule: body.logConfig.logBeginRule,
165
- }
166
- : undefined,
167
- customContainerConfig: body.customContainerConfig
168
- ? {
169
- image: body.customContainerConfig.image,
170
- entrypoint: body.customContainerConfig.entrypoint,
171
- command: body.customContainerConfig.command,
172
- port: body.customContainerConfig.port,
173
- accelerationType: body.customContainerConfig.accelerationType,
174
- }
175
- : undefined,
176
- description: body.description,
177
- internetAccess: body.internetAccess,
178
- role: body.role,
179
- codeChecksum: body.codeChecksum,
180
- codeSize: body.codeSize,
181
- createdTime: body.createdTime,
182
- lastModifiedTime: body.lastModifiedTime,
183
- state: body.state,
184
- stateReason: body.stateReason,
185
- stateReasonCode: body.stateReasonCode,
186
- lastUpdateStatus: body.lastUpdateStatus,
187
- lastUpdateStatusReason: body.lastUpdateStatusReason,
188
- lastUpdateStatusReasonCode: body.lastUpdateStatusReasonCode,
189
- };
190
- }
191
- catch (error) {
192
- if (error &&
193
- typeof error === 'object' &&
194
- 'code' in error &&
195
- error.code === 'FunctionNotFound') {
196
- return null;
197
- }
198
- throw error;
199
- }
200
- },
201
- updateFunctionConfiguration: async (config) => {
202
- const updateFunctionInput = new fc.UpdateFunctionInput({
203
- runtime: config.runtime,
204
- handler: config.handler,
205
- memorySize: config.memorySize,
206
- timeout: config.timeout,
207
- ...(config.diskSize && { diskSize: config.diskSize }),
208
- ...(config.environmentVariables && { environmentVariables: config.environmentVariables }),
209
- ...(config.gpuConfig && {
210
- gpuConfig: new fc.GPUConfig({
211
- gpuMemorySize: config.gpuConfig.gpuMemorySize,
212
- gpuType: config.gpuConfig.gpuType,
213
- }),
214
- }),
215
- ...(config.vpcConfig && {
216
- vpcConfig: new fc.VPCConfig({
217
- vpcId: config.vpcConfig.vpcId,
218
- vSwitchIds: config.vpcConfig.vSwitchIds,
219
- securityGroupId: config.vpcConfig.securityGroupId,
433
+ }),
220
434
  }),
221
- }),
222
- ...(config.nasConfig && {
223
- nasConfig: new fc.NASConfig({
224
- userId: config.nasConfig.userId,
225
- groupId: config.nasConfig.groupId,
226
- mountPoints: config.nasConfig.mountPoints?.map((mp) => new fc.NASMountConfig({
227
- serverAddr: mp.serverAddr,
228
- mountDir: mp.mountDir,
229
- enableTLS: mp.enableTls,
230
- })),
435
+ ...(config.logConfig && {
436
+ logConfig: new fc.LogConfig({
437
+ project: config.logConfig.project,
438
+ logstore: config.logConfig.logstore,
439
+ enableRequestMetrics: config.logConfig.enableRequestMetrics,
440
+ enableInstanceMetrics: config.logConfig.enableInstanceMetrics,
441
+ logBeginRule: config.logConfig.logBeginRule,
442
+ }),
231
443
  }),
232
- }),
233
- ...(config.logConfig && {
234
- logConfig: new fc.LogConfig({
235
- project: config.logConfig.project,
236
- logstore: config.logConfig.logstore,
237
- enableRequestMetrics: config.logConfig.enableRequestMetrics,
238
- enableInstanceMetrics: config.logConfig.enableInstanceMetrics,
239
- logBeginRule: config.logConfig.logBeginRule,
444
+ ...(config.customContainerConfig && {
445
+ customContainerConfig: new fc.CustomContainerConfig({
446
+ image: config.customContainerConfig.image,
447
+ entrypoint: config.customContainerConfig.entrypoint,
448
+ command: config.customContainerConfig.command,
449
+ port: config.customContainerConfig.port,
450
+ accelerationType: config.customContainerConfig.accelerationType,
451
+ }),
240
452
  }),
241
- }),
242
- ...(config.customContainerConfig && {
243
- customContainerConfig: new fc.CustomContainerConfig({
244
- image: config.customContainerConfig.image,
245
- entrypoint: config.customContainerConfig.entrypoint,
246
- command: config.customContainerConfig.command,
247
- port: config.customContainerConfig.port,
248
- accelerationType: config.customContainerConfig.accelerationType,
453
+ ...(config.description && { description: config.description }),
454
+ ...(config.internetAccess !== undefined && { internetAccess: config.internetAccess }),
455
+ ...(config.role && { role: config.role }),
456
+ });
457
+ const request = new fc.UpdateFunctionRequest({
458
+ body: updateFunctionInput,
459
+ });
460
+ // Wait for Active before issuing the update — updating a function that is
461
+ // still provisioning (e.g. right after create) races the platform.
462
+ await operations.waitForFunctionActive(config.functionName);
463
+ await fc3Client.updateFunction(config.functionName, request);
464
+ },
465
+ updateFunctionCode: async (functionName, codePath, ossCode) => {
466
+ const updateFunctionInput = new fc.UpdateFunctionInput({
467
+ code: buildCodeLocation(codePath, ossCode),
468
+ });
469
+ const request = new fc.UpdateFunctionRequest({
470
+ body: updateFunctionInput,
471
+ });
472
+ await operations.waitForFunctionActive(functionName);
473
+ await fc3Client.updateFunction(functionName, request);
474
+ },
475
+ deleteFunction: async (functionName) => {
476
+ await fc3Client.deleteFunction(functionName);
477
+ // DeleteFunction returns immediately — wait for the function to be gone so
478
+ // a subsequent create (retry) does not collide with a still-deleting function.
479
+ await operations.waitForFunctionDeleted(functionName);
480
+ },
481
+ createTrigger: async (functionName, triggerName, triggerType, triggerConfig, qualifier) => {
482
+ const createTriggerInput = new fc.CreateTriggerInput({
483
+ triggerName,
484
+ triggerType,
485
+ triggerConfig: JSON.stringify(triggerConfig),
486
+ ...(qualifier ? { qualifier } : {}),
487
+ });
488
+ const request = new fc.CreateTriggerRequest({
489
+ body: createTriggerInput,
490
+ });
491
+ await fc3Client.createTrigger(functionName, request);
492
+ },
493
+ deleteTrigger: async (functionName, triggerName) => {
494
+ await fc3Client.deleteTrigger(functionName, triggerName);
495
+ },
496
+ createCustomDomain: async (domainName, protocol, fnName, certConfig) => {
497
+ const createCustomDomainInput = new fc.CreateCustomDomainInput({
498
+ domainName,
499
+ protocol,
500
+ ...(certConfig ? { certConfig: new fc.CertConfig(certConfig) } : {}),
501
+ routeConfig: new fc.RouteConfig({
502
+ routes: [
503
+ new fc.PathConfig({
504
+ path: '/*',
505
+ functionName: fnName,
506
+ }),
507
+ ],
249
508
  }),
250
- }),
251
- ...(config.description && { description: config.description }),
252
- ...(config.internetAccess !== undefined && { internetAccess: config.internetAccess }),
253
- ...(config.role && { role: config.role }),
254
- });
255
- const request = new fc.UpdateFunctionRequest({
256
- body: updateFunctionInput,
257
- });
258
- await fc3Client.updateFunction(config.functionName, request);
259
- },
260
- updateFunctionCode: async (functionName, codePath, ossCode) => {
261
- const updateFunctionInput = new fc.UpdateFunctionInput({
262
- code: buildCodeLocation(codePath, ossCode),
263
- });
264
- const request = new fc.UpdateFunctionRequest({
265
- body: updateFunctionInput,
266
- });
267
- await fc3Client.updateFunction(functionName, request);
268
- },
269
- deleteFunction: async (functionName) => {
270
- await fc3Client.deleteFunction(functionName);
271
- },
272
- });
509
+ });
510
+ const request = new fc.CreateCustomDomainRequest({
511
+ body: createCustomDomainInput,
512
+ });
513
+ await fc3Client.createCustomDomain(request);
514
+ },
515
+ getCustomDomain: async (domainName) => {
516
+ try {
517
+ const response = await fc3Client.getCustomDomain(domainName);
518
+ if (!response || !response.body)
519
+ return null;
520
+ return {
521
+ domainName: response.body.domainName,
522
+ protocol: response.body.protocol,
523
+ certConfig: response.body.certConfig
524
+ ? {
525
+ certName: response.body.certConfig.certName,
526
+ certificateId: response.body.certConfig.certificateId,
527
+ }
528
+ : undefined,
529
+ };
530
+ }
531
+ catch (error) {
532
+ if (error &&
533
+ typeof error === 'object' &&
534
+ 'code' in error &&
535
+ error.code === 'CustomDomainNotFound') {
536
+ return null;
537
+ }
538
+ throw error;
539
+ }
540
+ },
541
+ deleteCustomDomain: async (domainName) => {
542
+ await fc3Client.deleteCustomDomain(domainName);
543
+ },
544
+ };
545
+ return operations;
546
+ };
273
547
  exports.createFc3Operations = createFc3Operations;