@geek-fun/serverlessinsight 0.9.1 → 0.9.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 (124) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
  3. package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +4 -8
  4. package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -8
  5. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
  6. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
  7. package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +132 -0
  8. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
  9. package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
  10. package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +20 -5
  11. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
  12. package/AGENTS.md +10 -0
  13. package/CHANGELOG.md +51 -0
  14. package/README.md +103 -13
  15. package/README.zh-CN.md +73 -13
  16. package/codecov +0 -0
  17. package/codecov.SHA256SUM +1 -0
  18. package/codecov.SHA256SUM.sig +16 -0
  19. package/dist/package.json +1 -1
  20. package/dist/src/commands/index.js +92 -24
  21. package/dist/src/commands/local.js +16 -3
  22. package/dist/src/commands/plan.js +31 -4
  23. package/dist/src/commands/schema.js +24 -0
  24. package/dist/src/commands/show.js +64 -10
  25. package/dist/src/commands/validate.js +34 -2
  26. package/dist/src/common/aliyunClient/apigwOperations.js +17 -1
  27. package/dist/src/common/aliyunClient/fc3Operations.js +39 -2
  28. package/dist/src/common/aliyunClient/ossOperations.js +214 -221
  29. package/dist/src/common/bucketPolicy.js +63 -0
  30. package/dist/src/common/constants.js +7 -1
  31. package/dist/src/common/domainUtils.js +4 -1
  32. package/dist/src/common/functionDefinition.js +25 -0
  33. package/dist/src/common/index.js +4 -0
  34. package/dist/src/common/jsonOutput.js +82 -0
  35. package/dist/src/common/logger.js +6 -3
  36. package/dist/src/common/nameBuilder.js +3 -1
  37. package/dist/src/common/noColor.js +9 -0
  38. package/dist/src/common/planCapabilities.js +119 -0
  39. package/dist/src/common/planCompare.js +119 -66
  40. package/dist/src/common/planFormatter.js +34 -20
  41. package/dist/src/common/planRedaction.js +26 -0
  42. package/dist/src/common/refreshPlanner.js +66 -21
  43. package/dist/src/common/siCron.js +415 -0
  44. package/dist/src/common/stateBackend/saasStateBackend.js +5 -4
  45. package/dist/src/common/tencentClient/cosOperations.js +326 -322
  46. package/dist/src/common/tencentClient/scfOperations.js +11 -2
  47. package/dist/src/common/tencentClient/tdsqlcOperations.js +6 -11
  48. package/dist/src/common/triggerMapper.js +16 -1
  49. package/dist/src/common/volcengineClient/apigwOperations.js +82 -0
  50. package/dist/src/common/volcengineClient/iamOperations.js +27 -3
  51. package/dist/src/common/volcengineClient/tosOperations.js +62 -56
  52. package/dist/src/common/volcengineClient/vefaasOperations.js +45 -0
  53. package/dist/src/lang/en.js +70 -3
  54. package/dist/src/lang/index.js +36 -1
  55. package/dist/src/lang/zh-CN.js +70 -3
  56. package/dist/src/parser/eventParser.js +1 -0
  57. package/dist/src/parser/functionParser.js +48 -2
  58. package/dist/src/stack/aliyunStack/apigwExecutor.js +1 -1
  59. package/dist/src/stack/aliyunStack/apigwPlanner.js +103 -23
  60. package/dist/src/stack/aliyunStack/apigwResource.js +4 -3
  61. package/dist/src/stack/aliyunStack/apigwTypes.js +3 -7
  62. package/dist/src/stack/aliyunStack/deployer.js +2 -0
  63. package/dist/src/stack/aliyunStack/esServerlessTypes.js +8 -4
  64. package/dist/src/stack/aliyunStack/fc3Executor.js +7 -3
  65. package/dist/src/stack/aliyunStack/fc3Planner.js +148 -153
  66. package/dist/src/stack/aliyunStack/fc3Resource.js +206 -53
  67. package/dist/src/stack/aliyunStack/fc3Types.js +30 -16
  68. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  69. package/dist/src/stack/aliyunStack/ossResource.js +113 -102
  70. package/dist/src/stack/aliyunStack/ossTypes.js +20 -20
  71. package/dist/src/stack/localStack/aliyunFc.js +1 -6
  72. package/dist/src/stack/localStack/event.js +31 -71
  73. package/dist/src/stack/localStack/function.js +25 -77
  74. package/dist/src/stack/localStack/functionRunner.js +10 -2
  75. package/dist/src/stack/localStack/httpAdapter.js +54 -0
  76. package/dist/src/stack/localStack/httpError.js +5 -0
  77. package/dist/src/stack/localStack/index.js +8 -1
  78. package/dist/src/stack/localStack/legacyLambda.js +26 -0
  79. package/dist/src/stack/localStack/localContext.js +29 -0
  80. package/dist/src/stack/localStack/localRoute.js +12 -0
  81. package/dist/src/stack/localStack/localRuntimes.js +22 -0
  82. package/dist/src/stack/localStack/localServer.js +8 -3
  83. package/dist/src/stack/localStack/requestBody.js +24 -0
  84. package/dist/src/stack/localStack/requestId.js +18 -0
  85. package/dist/src/stack/localStack/tencent.js +147 -0
  86. package/dist/src/stack/localStack/timer.js +183 -0
  87. package/dist/src/stack/localStack/utils.js +19 -1
  88. package/dist/src/stack/localStack/volcengine.js +68 -0
  89. package/dist/src/stack/scfStack/cosPlanner.js +9 -14
  90. package/dist/src/stack/scfStack/cosResource.js +42 -50
  91. package/dist/src/stack/scfStack/cosTypes.js +19 -14
  92. package/dist/src/stack/scfStack/deployer.js +2 -0
  93. package/dist/src/stack/scfStack/scfExecutor.js +7 -3
  94. package/dist/src/stack/scfStack/scfHttpTrigger.js +106 -0
  95. package/dist/src/stack/scfStack/scfPlanner.js +114 -29
  96. package/dist/src/stack/scfStack/scfResource.js +329 -311
  97. package/dist/src/stack/scfStack/scfTypes.js +4 -3
  98. package/dist/src/stack/scfStack/tdsqlcPlanner.js +10 -13
  99. package/dist/src/stack/volcengineStack/apigwDomains.js +64 -0
  100. package/dist/src/stack/volcengineStack/apigwPlanner.js +71 -15
  101. package/dist/src/stack/volcengineStack/apigwResource.js +60 -24
  102. package/dist/src/stack/volcengineStack/apigwTypes.js +5 -1
  103. package/dist/src/stack/volcengineStack/deployer.js +6 -0
  104. package/dist/src/stack/volcengineStack/tosPlanner.js +8 -13
  105. package/dist/src/stack/volcengineStack/tosResource.js +22 -35
  106. package/dist/src/stack/volcengineStack/tosTypes.js +5 -8
  107. package/dist/src/stack/volcengineStack/vefaasPlanner.js +186 -44
  108. package/dist/src/stack/volcengineStack/vefaasResource.js +232 -14
  109. package/dist/src/stack/volcengineStack/vefaasTypes.js +6 -3
  110. package/dist/src/validator/functionSchema.js +25 -2
  111. package/dist/src/validator/iacSchema.js +2 -1
  112. package/dist/src/validator/index.js +4 -1
  113. package/dist/src/validator/rootSchema.js +49 -18
  114. package/dist/src/validator/schemaExport.js +60 -0
  115. package/dist/src/validator/semanticValidation.js +79 -0
  116. package/dist/src/validator/templateRefSchema.js +9 -1
  117. package/dist/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +1 -1
  119. package/release-notes.md +79 -0
  120. package/samples/aliyun-poc-timer.yml +39 -0
  121. package/samples/tencent-local/index.js +13 -0
  122. package/samples/tencent-local/serverlessinsight.yml +23 -0
  123. package/samples/volcengine-local/index.js +13 -0
  124. package/samples/volcengine-local/serverlessinsight.yml +28 -0
@@ -4,13 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.deleteResource = exports.updateResource = exports.readResource = exports.createResource = exports.deriveFc3ExecutionStatements = exports.resolveRoleGrant = void 0;
7
+ const functionDefinition_1 = require("../../common/functionDefinition");
8
+ const planCompare_1 = require("../../common/planCompare");
9
+ const fc3Types_1 = require("./fc3Types");
10
+ const triggerMapper_1 = require("../../common/triggerMapper");
7
11
  const aliyunClient_1 = require("../../common/aliyunClient");
8
12
  const node_fs_1 = __importDefault(require("node:fs"));
9
13
  const node_path_1 = __importDefault(require("node:path"));
10
14
  const common_1 = require("../../common");
11
15
  const constants_1 = require("../../common/constants");
12
16
  const types_1 = require("../../types");
13
- const fc3Types_1 = require("./fc3Types");
17
+ const siCron_1 = require("../../common/siCron");
18
+ const fc3Types_2 = require("./fc3Types");
14
19
  const slsOperations_1 = require("../../common/aliyunClient/slsOperations");
15
20
  const ecsOperations_1 = require("../../common/aliyunClient/ecsOperations");
16
21
  const logger_1 = require("../../common/logger");
@@ -289,14 +294,136 @@ const buildFc3InstanceFromProvider = (info, sid) => {
289
294
  })),
290
295
  };
291
296
  };
292
- const buildHttpTriggerConfig = (trigger) => {
293
- const authType = (0, common_1.mapAuthType)(common_1.ProviderEnum.ALIYUN, trigger.auth_type);
294
- const { disableURLInternet } = (0, common_1.mapAliyunAccess)(trigger.access);
295
- return {
296
- authType,
297
- methods: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH'],
298
- ...(disableURLInternet !== undefined ? { disableURLInternet } : {}),
299
- };
297
+ const buildHttpTriggerConfig = triggerMapper_1.buildAliyunHttpTriggerConfig;
298
+ const TIMER_TRIGGER_INSTANCE_TYPE = 'ALIYUN_FC3_TIMER_TRIGGER';
299
+ /** FC3 timer dialect: 6-field cron (UTC+8), payload passthrough, enable flag. */
300
+ const buildFc3TimerTriggerConfig = (timer) => ({
301
+ payload: timer.payload ?? '',
302
+ cronExpression: (0, siCron_1.translateSiCron)(timer.cron, 'aliyun'),
303
+ enable: timer.enable,
304
+ ...(timer.description !== undefined ? { description: timer.description } : {}),
305
+ });
306
+ const normalizeLiveTimerConfig = (config, description) => ({
307
+ payload: typeof config?.payload === 'string' ? config.payload : '',
308
+ cronExpression: typeof config?.cronExpression === 'string' ? config.cronExpression : '',
309
+ enable: config?.enable === true || config?.enable === 'true',
310
+ ...(description ? { description } : {}),
311
+ });
312
+ const timerConfigFromAttributes = (attrs) => {
313
+ const cron = typeof attrs.cron === 'string' ? attrs.cron : undefined;
314
+ if (!cron) {
315
+ return null;
316
+ }
317
+ try {
318
+ return {
319
+ payload: typeof attrs.payload === 'string' ? attrs.payload : '',
320
+ cronExpression: (0, siCron_1.translateSiCron)(cron, 'aliyun'),
321
+ enable: attrs.enable !== false,
322
+ ...(typeof attrs.description === 'string' ? { description: attrs.description } : {}),
323
+ };
324
+ }
325
+ catch {
326
+ return null;
327
+ }
328
+ };
329
+ const buildTimerTriggerAttributes = (timer) => ({
330
+ cron: timer.cron,
331
+ ...(timer.payload !== undefined ? { payload: timer.payload } : {}),
332
+ enable: timer.enable,
333
+ ...(timer.description !== undefined ? { description: timer.description } : {}),
334
+ });
335
+ const buildTimerTriggerInstance = (context, fn, timer) => ({
336
+ type: TIMER_TRIGGER_INSTANCE_TYPE,
337
+ id: timer.name,
338
+ sid: (0, common_1.buildSid)('aliyun', 'fc3-timer-trigger', context.stage, `${fn.name}.${timer.name}`),
339
+ attributes: buildTimerTriggerAttributes(timer),
340
+ });
341
+ const isTriggerNotFound = (error) => error?.code === 'TriggerNotFound';
342
+ /**
343
+ * Reconcile the function's timer triggers against the provider (issue #258).
344
+ *
345
+ * The live trigger list is the reconcile baseline, so cloud-side edits
346
+ * (console cron change, manual delete, extra triggers) converge on every
347
+ * deploy — not just when local state disagrees. When the probe fails the
348
+ * state-recorded instances take over as the baseline. Name is the drift key:
349
+ * si-cron stays the stored form and is translated only at the edge.
350
+ */
351
+ const reconcileFc3TimerTriggers = async (context, fn, previousInstances, client) => {
352
+ const desiredTimers = fn.triggers?.timer ?? [];
353
+ const previousTimers = previousInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
354
+ if (desiredTimers.length === 0 && previousTimers.length === 0) {
355
+ return [];
356
+ }
357
+ let liveTimers = [];
358
+ let liveAvailable = true;
359
+ try {
360
+ liveTimers = (await client.fc3.listTriggers(fn.name))
361
+ .filter((trigger) => trigger.triggerType === 'timer' && trigger.triggerName)
362
+ .map((trigger) => ({
363
+ name: trigger.triggerName,
364
+ config: normalizeLiveTimerConfig((trigger.triggerConfig ?? {}), trigger.description || undefined),
365
+ }));
366
+ }
367
+ catch (error) {
368
+ liveAvailable = false;
369
+ logger_1.logger.warn(lang_1.lang.__('PLAN_TIMER_TRIGGER_PROBE_FAILED', { functionName: fn.name, error: String(error) }));
370
+ }
371
+ const baseline = liveAvailable
372
+ ? liveTimers
373
+ : previousTimers.flatMap((instance) => {
374
+ const config = timerConfigFromAttributes(instance.attributes ?? {});
375
+ return config ? [{ name: instance.id, config }] : [];
376
+ });
377
+ const resultingInstances = [];
378
+ for (const timer of desiredTimers) {
379
+ const desiredConfig = buildFc3TimerTriggerConfig(timer);
380
+ const live = baseline.find((entry) => entry.name === timer.name);
381
+ if (!live) {
382
+ logger_1.logger.info(lang_1.lang.__('CREATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
383
+ }
384
+ else if (!(0, common_1.attributesEqual)(live.config, desiredConfig)) {
385
+ logger_1.logger.info(lang_1.lang.__('UPDATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
386
+ try {
387
+ await client.fc3.deleteTrigger(fn.name, timer.name);
388
+ }
389
+ catch (error) {
390
+ if (!isTriggerNotFound(error))
391
+ throw error;
392
+ }
393
+ }
394
+ else {
395
+ resultingInstances.push(buildTimerTriggerInstance(context, fn, timer));
396
+ continue;
397
+ }
398
+ try {
399
+ await client.fc3.createTrigger(fn.name, timer.name, 'timer', desiredConfig, undefined, timer.description);
400
+ }
401
+ catch (error) {
402
+ // a leftover trigger from an adopted function may already carry the name
403
+ if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error))
404
+ throw error;
405
+ logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_ALREADY_ATTACHED', {
406
+ triggerName: timer.name,
407
+ functionName: fn.name,
408
+ }));
409
+ }
410
+ logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_CREATED', { triggerName: timer.name, functionName: fn.name }));
411
+ resultingInstances.push(buildTimerTriggerInstance(context, fn, timer));
412
+ }
413
+ const desiredNames = new Set(desiredTimers.map((timer) => timer.name));
414
+ for (const stale of baseline.filter((entry) => !desiredNames.has(entry.name))) {
415
+ logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', { triggerName: stale.name, functionName: fn.name }));
416
+ try {
417
+ await client.fc3.deleteTrigger(fn.name, stale.name);
418
+ logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName: stale.name }));
419
+ }
420
+ catch (error) {
421
+ if (!isTriggerNotFound(error))
422
+ throw error;
423
+ logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: stale.name }));
424
+ }
425
+ }
426
+ return resultingInstances;
300
427
  };
301
428
  const createDependentResources = async (context, fn, serviceName, existingInstances = [], state, options) => {
302
429
  const client = (0, aliyunClient_1.createAliyunClient)(context);
@@ -569,7 +696,7 @@ const createResource = async (context, fn, state) => {
569
696
  const stateWithSharedProject = dependentResources.sharedProject
570
697
  ? (0, common_1.setSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY, dependentResources.sharedProject)
571
698
  : state;
572
- let config = (0, fc3Types_1.functionToFc3Config)(fn);
699
+ let config = (0, fc3Types_2.functionToFc3Config)(fn);
573
700
  config = {
574
701
  ...config,
575
702
  tags: [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }],
@@ -604,21 +731,17 @@ const createResource = async (context, fn, state) => {
604
731
  if (dependentResources.nasConfig) {
605
732
  config = {
606
733
  ...config,
607
- nasConfig: {
608
- userId: -1,
609
- groupId: -1,
610
- mountPoints: dependentResources.nasConfig.mountPoints.map((mp) => ({
611
- serverAddr: mp.serverAddr,
612
- mountDir: mp.mountDir,
613
- })),
614
- },
734
+ nasConfig: (0, fc3Types_1.buildFc3NasConfig)(dependentResources.nasConfig.mountPoints.map((mp) => ({
735
+ serverAddr: mp.serverAddr,
736
+ mountDir: mp.mountDir,
737
+ }))),
615
738
  };
616
739
  }
617
740
  // Container-only functions have no code block — mirror the planner's null
618
741
  // codeHash (PR #237); the image lives in customContainerConfig, no zip push.
619
742
  const codePath = fn.code?.path;
620
743
  const codeHash = codePath ? await (0, common_1.computeZipContentHash)(codePath) : null;
621
- const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
744
+ const baseDefinition = (0, fc3Types_2.extractFc3Definition)(config, codeHash, fn);
622
745
  const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
623
746
  const dependentInstances = dependentResources.instances.map((dep) => ({
624
747
  sid: dep.sid ??
@@ -744,6 +867,7 @@ const createResource = async (context, fn, state) => {
744
867
  attributes: { ...triggerConfig },
745
868
  });
746
869
  }
870
+ lifecycleInstances.push(...(await reconcileFc3TimerTriggers(context, fn, [], client)));
747
871
  if (fn.domain) {
748
872
  logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
749
873
  let certConfig;
@@ -776,7 +900,13 @@ const createResource = async (context, fn, state) => {
776
900
  mode: 'managed',
777
901
  region: context.region,
778
902
  definition,
779
- instances: [fcInstance, ...lifecycleInstances, ...dependentInstances],
903
+ // DependentInstance's optional sid is always filled by construction here —
904
+ // widened to ResourceInstance at the state boundary
905
+ instances: [
906
+ fcInstance,
907
+ ...lifecycleInstances,
908
+ ...dependentInstances,
909
+ ],
780
910
  lastUpdated: new Date().toISOString(),
781
911
  status: 'ready',
782
912
  };
@@ -799,11 +929,12 @@ const withRecreatedMountTargets = (instances, recreated) => instances.map((insta
799
929
  const liveDomain = recreated[fileSystemId];
800
930
  return liveDomain ? { ...instance, id: `${fileSystemId}/${liveDomain}` } : instance;
801
931
  });
802
- const updateResource = async (context, fn, state, options) => {
932
+ const updateResource = async (context, providedFn, state, options) => {
803
933
  const ctx = (0, common_1.getContext)();
804
934
  const serviceName = `${ctx.app}-${ctx.service}`;
805
- const logicalId = `functions.${fn.key}`;
935
+ const logicalId = `functions.${providedFn.key}`;
806
936
  const existingState = (0, common_1.getResource)(state, logicalId);
937
+ const fn = (0, functionDefinition_1.withStoredFunctionIam)(providedFn, existingState?.definition);
807
938
  const existingInstances = (existingState?.instances ?? []);
808
939
  const hasSlsResources = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT' ||
809
940
  i.type === 'ALIYUN_SLS_LOGSTORE' ||
@@ -837,7 +968,7 @@ const updateResource = async (context, fn, state, options) => {
837
968
  }
838
969
  else if (hasSlsResources) {
839
970
  const slsLogstoreInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
840
- if (fn.log) {
971
+ if (fn.log !== false) {
841
972
  if (slsLogstoreInstance) {
842
973
  const [projectName, logstoreName] = slsLogstoreInstance.id.split('/');
843
974
  logConfig = { project: projectName, logstore: logstoreName };
@@ -866,6 +997,7 @@ const updateResource = async (context, fn, state, options) => {
866
997
  }
867
998
  catch (error) {
868
999
  logger_1.logger.warn(lang_1.lang.__('NESTED_REPAIR_FAILED', { resource: logstoreName, error: String(error) }));
1000
+ throw error;
869
1001
  }
870
1002
  }
871
1003
  }
@@ -937,7 +1069,7 @@ const updateResource = async (context, fn, state, options) => {
937
1069
  const existingIam = existingState?.definition?.iam;
938
1070
  const desiredIam = fn.iam;
939
1071
  const iamChanged = !(0, common_1.attributesEqual)(existingIam ?? {}, desiredIam ?? {});
940
- if (iamChanged) {
1072
+ if (iamChanged || options?.force) {
941
1073
  // Check for statement changes
942
1074
  const desiredStatements = newIamRole ? newIamRole.statements : undefined;
943
1075
  const existingRole = existingIam?.role;
@@ -954,7 +1086,9 @@ const updateResource = async (context, fn, state, options) => {
954
1086
  : undefined;
955
1087
  const desiredManagedPoliciesVal = (desiredManagedPolicies ?? []);
956
1088
  const existingManagedPoliciesVal = (existingManagedPolicies ?? []);
957
- if (!(0, common_1.attributesEqual)(existingManagedPoliciesVal, desiredManagedPoliciesVal)) {
1089
+ if (desiredManagedPolicies !== undefined &&
1090
+ (options?.force ||
1091
+ !(0, common_1.attributesEqual)(existingManagedPoliciesVal, desiredManagedPoliciesVal))) {
958
1092
  await client.ram.updateManagedPolicies(ramRoleInstance.id, desiredManagedPolicies ?? []);
959
1093
  }
960
1094
  }
@@ -1032,6 +1166,7 @@ const updateResource = async (context, fn, state, options) => {
1032
1166
  }
1033
1167
  catch (error) {
1034
1168
  logger_1.logger.warn(lang_1.lang.__('NESTED_REPAIR_FAILED', { resource: sgInstance.id, error: String(error) }));
1169
+ throw error;
1035
1170
  }
1036
1171
  }
1037
1172
  }
@@ -1078,6 +1213,7 @@ const updateResource = async (context, fn, state, options) => {
1078
1213
  }
1079
1214
  catch (error) {
1080
1215
  logger_1.logger.warn(lang_1.lang.__('NESTED_REPAIR_FAILED', { resource: failingFsId ?? 'nas', error: String(error) }));
1216
+ throw error;
1081
1217
  }
1082
1218
  }
1083
1219
  if (mountTargetInstances.length > 0 && nasStorageItems.length > 0) {
@@ -1095,7 +1231,7 @@ const updateResource = async (context, fn, state, options) => {
1095
1231
  };
1096
1232
  }
1097
1233
  }
1098
- let config = (0, fc3Types_1.functionToFc3Config)(fn);
1234
+ let config = (0, fc3Types_2.functionToFc3Config)(fn);
1099
1235
  if (logConfig) {
1100
1236
  config = {
1101
1237
  ...config,
@@ -1126,11 +1262,7 @@ const updateResource = async (context, fn, state, options) => {
1126
1262
  if (nasConfig) {
1127
1263
  config = {
1128
1264
  ...config,
1129
- nasConfig: {
1130
- userId: -1,
1131
- groupId: -1,
1132
- mountPoints: nasConfig.mountPoints,
1133
- },
1265
+ nasConfig: (0, fc3Types_1.buildFc3NasConfig)(nasConfig.mountPoints),
1134
1266
  };
1135
1267
  }
1136
1268
  const codePath = fn.code?.path;
@@ -1138,10 +1270,10 @@ const updateResource = async (context, fn, state, options) => {
1138
1270
  const desiredCodeHash = codePath ? await (0, common_1.computeZipContentHash)(codePath) : null;
1139
1271
  const codeChanged = codePath ? currentCodeHash !== desiredCodeHash : false;
1140
1272
  const existingConfig = existingState?.definition;
1141
- const desiredDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
1142
- const { codeHash: _existingCodeHash, iam: _existingIam, ...existingConfigOnly } = existingConfig || {};
1143
- const { codeHash: _desiredCodeHash, ...desiredConfigOnly } = desiredDefinition;
1144
- const configChanged = !(0, common_1.attributesEqual)(existingConfigOnly, desiredConfigOnly);
1273
+ const desiredDefinition = (0, fc3Types_2.extractFc3Definition)(config, desiredCodeHash, fn);
1274
+ const { codeHash: _existingCodeHash, iam: _existingIam, http: _existingHttp, domain: _existingDomain, timers: _existingTimers, ...existingConfigOnly } = existingConfig || {};
1275
+ const { codeHash: _desiredCodeHash, http: _desiredHttp, domain: _desiredDomain, timers: _desiredTimers, ...desiredConfigOnly } = desiredDefinition;
1276
+ const configChanged = (0, planCompare_1.definitionsDiffer)(existingConfigOnly, desiredConfigOnly);
1145
1277
  // `force` carries the plan's drifted flag: a live-drift update (state
1146
1278
  // matches config, cloud edited in console) must re-push the config even
1147
1279
  // though state-vs-desired sees no change.
@@ -1193,23 +1325,10 @@ const updateResource = async (context, fn, state, options) => {
1193
1325
  await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', triggerConfig);
1194
1326
  logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
1195
1327
  }
1196
- else if (!desiredHttpTrigger && existingHttpTrigger) {
1197
- logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
1198
- try {
1199
- await client.fc3.deleteTrigger(fn.name, 'http-trigger');
1200
- logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: 'http-trigger' }));
1201
- }
1202
- catch (err) {
1203
- const errorCode = err?.code;
1204
- if (errorCode !== 'TriggerNotFound')
1205
- throw err;
1206
- logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: 'http-trigger' }));
1207
- }
1208
- }
1209
1328
  else if (desiredHttpTrigger && existingHttpTrigger) {
1210
1329
  const desiredTriggerConfig = buildHttpTriggerConfig(desiredHttpTrigger);
1211
1330
  const existingAttrs = existingHttpTrigger.attributes ?? {};
1212
- if (!(0, common_1.attributesEqual)(desiredTriggerConfig, existingAttrs)) {
1331
+ if (options?.repairHttp || !(0, common_1.attributesEqual)(desiredTriggerConfig, existingAttrs)) {
1213
1332
  logger_1.logger.info(lang_1.lang.__('UPDATING_HTTP_TRIGGER', { functionName: fn.name }));
1214
1333
  try {
1215
1334
  await client.fc3.deleteTrigger(fn.name, 'http-trigger');
@@ -1223,8 +1342,22 @@ const updateResource = async (context, fn, state, options) => {
1223
1342
  logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
1224
1343
  }
1225
1344
  }
1345
+ else if (!desiredHttpTrigger && existingHttpTrigger) {
1346
+ logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
1347
+ try {
1348
+ await client.fc3.deleteTrigger(fn.name, 'http-trigger');
1349
+ logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: 'http-trigger' }));
1350
+ }
1351
+ catch (err) {
1352
+ const errorCode = err?.code;
1353
+ if (errorCode !== 'TriggerNotFound')
1354
+ throw err;
1355
+ logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: 'http-trigger' }));
1356
+ }
1357
+ }
1226
1358
  const existingCustomDomain = existingInstances.find((i) => i.type === 'ALIYUN_FC3_CUSTOM_DOMAIN');
1227
1359
  const desiredDomain = fn.domain;
1360
+ const timerInstances = await reconcileFc3TimerTriggers(context, fn, existingInstances, client);
1228
1361
  if (desiredDomain && !existingCustomDomain) {
1229
1362
  logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: desiredDomain.domain_name }));
1230
1363
  let certConfig;
@@ -1261,7 +1394,9 @@ const updateResource = async (context, fn, state, options) => {
1261
1394
  }
1262
1395
  else if (desiredDomain && existingCustomDomain) {
1263
1396
  const existingProtocol = existingCustomDomain.attributes?.protocol;
1264
- const domainChanged = desiredDomain.domain_name !== existingCustomDomain.id ||
1397
+ const domainChanged = options?.repairDomain ||
1398
+ !(0, common_1.attributesEqual)(existingState?.definition?.domain ?? {}, desiredDomain) ||
1399
+ desiredDomain.domain_name !== existingCustomDomain.id ||
1265
1400
  desiredDomain.protocol !== existingProtocol;
1266
1401
  if (domainChanged) {
1267
1402
  logger_1.logger.info(lang_1.lang.__('UPDATING_CUSTOM_DOMAIN', { domainName: desiredDomain.domain_name }));
@@ -1295,7 +1430,7 @@ const updateResource = async (context, fn, state, options) => {
1295
1430
  throw new Error(lang_1.lang.__('REFRESH_STATE_FUNCTION', { name: fn.name }));
1296
1431
  }
1297
1432
  const codeHash = codePath ? await (0, common_1.computeZipContentHash)(codePath) : null;
1298
- const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
1433
+ const baseDefinition = (0, fc3Types_2.extractFc3Definition)(config, codeHash, fn);
1299
1434
  const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
1300
1435
  const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
1301
1436
  const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
@@ -1309,6 +1444,7 @@ const updateResource = async (context, fn, state, options) => {
1309
1444
  attributes: { ...triggerConfig },
1310
1445
  });
1311
1446
  }
1447
+ lifecycleInstances.push(...timerInstances);
1312
1448
  if (fn.domain) {
1313
1449
  lifecycleInstances.push({
1314
1450
  type: 'ALIYUN_FC3_CUSTOM_DOMAIN',
@@ -1320,6 +1456,7 @@ const updateResource = async (context, fn, state, options) => {
1320
1456
  const existingDependentInstances = existingInstances
1321
1457
  .filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION')
1322
1458
  .filter((i) => i.type !== 'ALIYUN_FC3_HTTP_TRIGGER')
1459
+ .filter((i) => i.type !== TIMER_TRIGGER_INSTANCE_TYPE)
1323
1460
  .filter((i) => i.type !== 'ALIYUN_FC3_CUSTOM_DOMAIN')
1324
1461
  .filter((i) => !(typeof fn.iam?.role === 'string' && i.type === 'ALIYUN_RAM_ROLE'))
1325
1462
  .filter((i) => !(i.type === 'ALIYUN_RAM_ROLE' && droppedRamRoleIds.has(i.id)))
@@ -1345,7 +1482,7 @@ const updateResource = async (context, fn, state, options) => {
1345
1482
  const resourceState = {
1346
1483
  mode: 'managed',
1347
1484
  region: context.region,
1348
- definition,
1485
+ definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(existingState?.definition ?? {}, definition), definition, ['http', 'domain', 'timers']),
1349
1486
  instances: [
1350
1487
  fcInstance,
1351
1488
  ...lifecycleInstances,
@@ -1371,7 +1508,23 @@ const deleteResource = async (context, functionName, logicalId, state) => {
1371
1508
  const existingState = (0, common_1.getResource)(state, logicalId);
1372
1509
  const existingInstances = (existingState?.instances ?? []);
1373
1510
  const client = (0, aliyunClient_1.createAliyunClient)(context);
1374
- // Delete HTTP trigger and custom domain before function (they depend on it)
1511
+ // Delete timers, HTTP trigger and custom domain before function (they depend on it)
1512
+ const timerTriggerInstances = existingInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
1513
+ for (const timerInstance of timerTriggerInstances) {
1514
+ logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', {
1515
+ triggerName: timerInstance.id,
1516
+ functionName,
1517
+ }));
1518
+ try {
1519
+ await client.fc3.deleteTrigger(functionName, timerInstance.id);
1520
+ logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName: timerInstance.id }));
1521
+ }
1522
+ catch (err) {
1523
+ if (!isTriggerNotFound(err))
1524
+ throw err;
1525
+ logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: timerInstance.id }));
1526
+ }
1527
+ }
1375
1528
  const httpTriggerInstance = existingInstances.find((i) => i.type === 'ALIYUN_FC3_HTTP_TRIGGER');
1376
1529
  if (httpTriggerInstance) {
1377
1530
  logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: httpTriggerInstance.id, functionName }));
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cloudFc3ToDefinition = exports.extractFunctionDomainDefinition = exports.extractFc3Definition = exports.functionToFc3Config = void 0;
3
+ exports.resolveRecordedFc3NasConfig = exports.buildFc3NasConfig = exports.cloudFc3ToDefinition = exports.extractFunctionDomainDefinition = exports.extractFc3Definition = exports.functionToFc3Config = void 0;
4
+ const lang_1 = require("../../lang");
5
+ const functionDefinition_1 = require("../../common/functionDefinition");
4
6
  const types_1 = require("../../types");
5
7
  const common_1 = require("../../common");
6
8
  const gpuConfigMap = {
@@ -50,17 +52,6 @@ const functionToFc3Config = (fn) => {
50
52
  securityGroupId: fn.network.security_group.name,
51
53
  };
52
54
  }
53
- if (fn.storage?.nas && fn.storage.nas.length > 0) {
54
- config.nasConfig = {
55
- userId: 10003,
56
- groupId: 10003,
57
- mountPoints: fn.storage.nas.map((nas) => ({
58
- serverAddr: nas.storage_class,
59
- mountDir: nas.mount_path,
60
- enableTls: false,
61
- })),
62
- };
63
- }
64
55
  if (fn.log !== undefined) {
65
56
  config.logConfig = {
66
57
  enableRequestMetrics: fn.log,
@@ -70,8 +61,8 @@ const functionToFc3Config = (fn) => {
70
61
  return config;
71
62
  };
72
63
  exports.functionToFc3Config = functionToFc3Config;
73
- const extractFc3Definition = (config, codeHash) => {
74
- return {
64
+ const extractFc3Definition = (config, codeHash, fn) => {
65
+ return (0, functionDefinition_1.withFunctionLifecycle)({
75
66
  functionName: config.functionName,
76
67
  runtime: config.runtime,
77
68
  handler: config.handler,
@@ -83,14 +74,15 @@ const extractFc3Definition = (config, codeHash) => {
83
74
  gpuConfig: config.gpuConfig ?? null,
84
75
  customContainerConfig: config.customContainerConfig ?? null,
85
76
  nasConfig: config.nasConfig ?? null,
77
+ ...(fn?.storage?.nas?.length ? { nasStorage: fn.storage.nas } : {}),
86
78
  logConfig: config.logConfig ?? null,
87
79
  codeHash,
88
- };
80
+ }, fn);
89
81
  };
90
82
  exports.extractFc3Definition = extractFc3Definition;
91
83
  const extractFunctionDomainDefinition = (fn, codeHash) => {
92
84
  const config = (0, exports.functionToFc3Config)(fn);
93
- return (0, exports.extractFc3Definition)(config, codeHash);
85
+ return (0, exports.extractFc3Definition)(config, codeHash, fn);
94
86
  };
95
87
  exports.extractFunctionDomainDefinition = extractFunctionDomainDefinition;
96
88
  /**
@@ -153,3 +145,25 @@ const cloudFc3ToDefinition = (info) => {
153
145
  };
154
146
  };
155
147
  exports.cloudFc3ToDefinition = cloudFc3ToDefinition;
148
+ const buildFc3NasConfig = (mountPoints) => ({ userId: -1, groupId: -1, mountPoints });
149
+ exports.buildFc3NasConfig = buildFc3NasConfig;
150
+ const resolveRecordedFc3NasConfig = (config, fn, instances) => {
151
+ if (!fn.storage?.nas?.length)
152
+ return config;
153
+ const mounts = instances.filter((instance) => instance.type === 'ALIYUN_NAS_MOUNT_TARGET');
154
+ if (!fn.network && mounts.length === 0)
155
+ throw new Error(lang_1.lang.__('PLAN_NAS_NETWORK_REQUIRED', { logicalId: `functions.${fn.key}` }));
156
+ const { nasConfig: _unresolvedNas, ...rest } = config;
157
+ return {
158
+ ...rest,
159
+ ...(mounts.length
160
+ ? {
161
+ nasConfig: (0, exports.buildFc3NasConfig)(mounts.map((mount, index) => ({
162
+ serverAddr: `${mount.id.split('/')[1]}:/`,
163
+ mountDir: fn.storage.nas[index]?.mount_path ?? '/mnt/nas',
164
+ }))),
165
+ }
166
+ : {}),
167
+ };
168
+ };
169
+ exports.resolveRecordedFc3NasConfig = resolveRecordedFc3NasConfig;
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateBucketPlan = void 0;
7
+ const bucketPolicy_1 = require("../../common/bucketPolicy");
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
9
  const lang_1 = require("../../lang");
10
+ const types_1 = require("../../types");
9
11
  const aliyunClient_1 = require("../../common/aliyunClient");
10
12
  const refreshCache_1 = require("../../common/refreshCache");
11
13
  const concurrency_1 = require("../../common/concurrency");
@@ -25,7 +27,18 @@ const planBucketDeletion = (logicalId, definition) => ({
25
27
  const toOwnershipTags = (tags) => tags?.map((tag) => ({ Key: tag.key, Value: tag.value }));
26
28
  const normalizeDefinitionForDisplay = (definition) => {
27
29
  const { domainBound: _domainBound, ...rest } = definition;
28
- return rest;
30
+ return (0, bucketPolicy_1.normalizeBucketPolicyDefinition)(rest, 'aliyun');
31
+ };
32
+ const removedOssDependents = (bucket, currentState, desiredDefinition) => {
33
+ if (!currentState)
34
+ return {};
35
+ const domainName = bucket.domain?.domain_name || bucket.website?.domain;
36
+ const dnsRemoved = !domainName &&
37
+ (currentState.instances ?? []).some((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME);
38
+ return {
39
+ ...(0, bucketPolicy_1.removedBucketPolicy)(ossTypes_1.OSS_BUCKET_POLICY_INSTANCE_TYPE, currentState, desiredDefinition),
40
+ ...(dnsRemoved ? { domain: currentState.definition.domain ?? null } : {}),
41
+ };
29
42
  };
30
43
  const generateBucketPlan = async (context, state, buckets) => {
31
44
  if (!buckets || buckets.length === 0) {
@@ -68,6 +81,7 @@ const generateBucketPlan = async (context, state, buckets) => {
68
81
  })),
69
82
  cloudToDefinition: ossTypes_1.cloudOssToDefinition,
70
83
  normalizeForDisplay: normalizeDefinitionForDisplay,
84
+ removedDependents: removedOssDependents(bucket, currentState, desiredDefinition),
71
85
  extraUpdate: () => Promise.resolve({ update: domainBindingPending, drifted: false }),
72
86
  refresh: context.refresh,
73
87
  });