@geek-fun/serverlessinsight 0.6.12 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "description": "Full life cycle cross providers serverless application management for your fast-growing business.",
5
5
  "homepage": "https://serverlessinsight.geekfun.club",
6
6
  "main": "dist/src/index.js",
@@ -3,20 +3,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.diffAttributes = exports.attributesEqual = exports.computeFileHash = void 0;
6
+ exports.diffAttributes = exports.attributesEqual = exports.computeDirectoryHash = exports.computeFileHash = void 0;
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
- /**
10
- * Compute SHA-256 hash of a file.
11
- * Used for tracking external artifacts like function code zip files.
12
- * @param filePath - Path to the file to hash
13
- * @returns Hex-encoded SHA-256 hash of the file contents
14
- */
9
+ const node_path_1 = __importDefault(require("node:path"));
15
10
  const computeFileHash = (filePath) => {
16
11
  const fileBuffer = node_fs_1.default.readFileSync(filePath);
17
12
  return node_crypto_1.default.createHash('sha256').update(fileBuffer).digest('hex');
18
13
  };
19
14
  exports.computeFileHash = computeFileHash;
15
+ const computeDirectoryHash = (dirPath) => {
16
+ const files = [];
17
+ const collectFiles = (currentPath) => {
18
+ const entries = node_fs_1.default.readdirSync(currentPath, { withFileTypes: true });
19
+ for (const entry of entries) {
20
+ const fullPath = node_path_1.default.join(currentPath, entry.name);
21
+ if (entry.isDirectory()) {
22
+ collectFiles(fullPath);
23
+ }
24
+ else if (entry.isFile()) {
25
+ files.push(fullPath);
26
+ }
27
+ }
28
+ };
29
+ collectFiles(dirPath);
30
+ files.sort();
31
+ const hash = node_crypto_1.default.createHash('sha256');
32
+ for (const file of files) {
33
+ const relativePath = node_path_1.default.relative(dirPath, file).split(node_path_1.default.sep).join('/');
34
+ hash.update(relativePath);
35
+ const content = node_fs_1.default.readFileSync(file);
36
+ hash.update(content);
37
+ }
38
+ return hash.digest('hex');
39
+ };
40
+ exports.computeDirectoryHash = computeDirectoryHash;
20
41
  /**
21
42
  * Deep equality comparison for two values.
22
43
  * Handles primitives, objects, arrays, null, and undefined.
@@ -5,6 +5,32 @@ const common_1 = require("../../common");
5
5
  const aliyunClient_1 = require("../../common/aliyunClient");
6
6
  const fc3Types_1 = require("./fc3Types");
7
7
  const lang_1 = require("../../lang");
8
+ /**
9
+ * Provider-managed logConfig fields that are set by the system after creation.
10
+ * These should not be compared when detecting changes.
11
+ */
12
+ const PROVIDER_MANAGED_LOG_CONFIG_FIELDS = ['project', 'logstore', 'logBeginRule'];
13
+ /**
14
+ * Normalize definition for comparison by excluding provider-managed fields.
15
+ * This prevents false-positive change detection when the system populates
16
+ * fields like logConfig.project and logConfig.logstore after creation.
17
+ */
18
+ const normalizeDefinitionForComparison = (definition) => {
19
+ const { logConfig, ...rest } = definition;
20
+ if (!logConfig || typeof logConfig !== 'object') {
21
+ return definition;
22
+ }
23
+ const normalizedLogConfig = {};
24
+ for (const [key, value] of Object.entries(logConfig)) {
25
+ if (!PROVIDER_MANAGED_LOG_CONFIG_FIELDS.includes(key)) {
26
+ normalizedLogConfig[key] = value;
27
+ }
28
+ }
29
+ return {
30
+ ...rest,
31
+ logConfig: Object.keys(normalizedLogConfig).length > 0 ? normalizedLogConfig : null,
32
+ };
33
+ };
8
34
  const isSecurityGroupId = (value) => value.startsWith('sg-');
9
35
  const resolveSecurityGroupId = async (context, securityGroupName, vpcId) => {
10
36
  if (isSecurityGroupId(securityGroupName)) {
@@ -74,7 +100,7 @@ const generateFunctionPlan = async (context, state, functions) => {
74
100
  };
75
101
  }
76
102
  const currentDefinition = currentState.definition || {};
77
- const definitionChanged = !(0, common_1.attributesEqual)(currentDefinition, desiredDefinition);
103
+ const definitionChanged = !(0, common_1.attributesEqual)(normalizeDefinitionForComparison(currentDefinition), normalizeDefinitionForComparison(desiredDefinition));
78
104
  if (definitionChanged) {
79
105
  return {
80
106
  logicalId,
@@ -358,6 +358,7 @@ const createResource = async (context, fn, state) => {
358
358
  project: dependentResources.logConfig.project,
359
359
  logstore: dependentResources.logConfig.logstore,
360
360
  enableRequestMetrics: true,
361
+ enableInstanceMetrics: true,
361
362
  },
362
363
  };
363
364
  }
@@ -547,6 +548,7 @@ const updateResource = async (context, fn, state) => {
547
548
  project: logConfig.project,
548
549
  logstore: logConfig.logstore,
549
550
  enableRequestMetrics: true,
551
+ enableInstanceMetrics: true,
550
552
  },
551
553
  };
552
554
  }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.generateBucketPlan = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
4
8
  const aliyunClient_1 = require("../../common/aliyunClient");
5
9
  const ossTypes_1 = require("./ossTypes");
6
10
  const stateManager_1 = require("../../common/stateManager");
@@ -24,7 +28,17 @@ const generateBucketPlan = async (context, state, buckets) => {
24
28
  const logicalId = `buckets.${bucket.key}`;
25
29
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
26
30
  const config = (0, ossTypes_1.bucketToOssBucketConfig)(bucket);
27
- const desiredDefinition = (0, ossTypes_1.extractOssBucketDefinition)(config);
31
+ const websiteCodeHash = (() => {
32
+ if (!bucket.website?.code)
33
+ return undefined;
34
+ try {
35
+ return (0, hashUtils_1.computeDirectoryHash)(node_path_1.default.resolve(process.cwd(), bucket.website.code));
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ })();
41
+ const desiredDefinition = (0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash);
28
42
  if (!currentState) {
29
43
  return {
30
44
  logicalId,
@@ -136,11 +136,14 @@ const createBucketResource = async (context, bucket, state) => {
136
136
  const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
137
137
  const logicalId = `buckets.${bucket.key}`;
138
138
  const instances = [buildOssInstanceFromProvider(bucketInfo, sid)];
139
+ const websiteCodeHash = bucket.website?.code
140
+ ? (0, common_1.computeDirectoryHash)(node_path_1.default.resolve(process.cwd(), bucket.website.code))
141
+ : undefined;
139
142
  const partialResourceState = {
140
143
  mode: 'managed',
141
144
  region: context.region,
142
145
  definition: {
143
- ...(0, ossTypes_1.extractOssBucketDefinition)(config),
146
+ ...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
144
147
  ...(bucket.website?.domain != null ? { domainBound: null } : {}),
145
148
  },
146
149
  instances,
@@ -224,7 +227,7 @@ const createBucketResource = async (context, bucket, state) => {
224
227
  mode: 'managed',
225
228
  region: context.region,
226
229
  definition: {
227
- ...(0, ossTypes_1.extractOssBucketDefinition)(config),
230
+ ...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
228
231
  ...(bucket.website?.domain != null
229
232
  ? { domainBound: cnameInfo?.bucketCnameBound ?? null }
230
233
  : {}),
@@ -260,6 +263,9 @@ const updateBucketResource = async (context, bucket, state) => {
260
263
  const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
261
264
  const logicalId = `buckets.${bucket.key}`;
262
265
  const instances = [buildOssInstanceFromProvider(bucketInfo, sid)];
266
+ const websiteCodeHash = bucket.website?.code
267
+ ? (0, common_1.computeDirectoryHash)(node_path_1.default.resolve(process.cwd(), bucket.website.code))
268
+ : undefined;
263
269
  const existingState = state.resources[logicalId];
264
270
  const existingDnsInstances = existingState?.instances?.filter((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME);
265
271
  const existingPrimaryDnsInstance = existingDnsInstances?.find((i) => !i.isWwwVariant);
@@ -338,7 +344,7 @@ const updateBucketResource = async (context, bucket, state) => {
338
344
  mode: 'managed',
339
345
  region: context.region,
340
346
  definition: {
341
- ...(0, ossTypes_1.extractOssBucketDefinition)(config),
347
+ ...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
342
348
  ...(bucket.website?.domain != null
343
349
  ? { domainBound: cnameInfo?.bucketCnameBound ?? null }
344
350
  : {}),
@@ -57,7 +57,7 @@ const bucketToOssBucketConfig = (bucket) => {
57
57
  return config;
58
58
  };
59
59
  exports.bucketToOssBucketConfig = bucketToOssBucketConfig;
60
- const extractOssBucketDefinition = (config) => {
60
+ const extractOssBucketDefinition = (config, websiteCodeHash) => {
61
61
  return {
62
62
  bucketName: config.bucketName,
63
63
  acl: config.acl ?? null,
@@ -67,6 +67,7 @@ const extractOssBucketDefinition = (config) => {
67
67
  errorDocument: config.websiteConfig.errorDocument ?? null,
68
68
  }
69
69
  : {},
70
+ websiteCodeHash: websiteCodeHash ?? null,
70
71
  storageClass: config.storageClass ?? null,
71
72
  domain: config.domain ?? null,
72
73
  wwwBindApex: config.wwwBindApex ?? false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "description": "Full life cycle cross providers serverless application management for your fast-growing business.",
5
5
  "homepage": "https://serverlessinsight.geekfun.club",
6
6
  "main": "dist/src/index.js",