@geek-fun/serverlessinsight 0.7.4 → 0.7.5

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.7.4",
3
+ "version": "0.7.5",
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",
@@ -25,7 +25,12 @@ const readCodeSize = (location) => {
25
25
  };
26
26
  exports.readCodeSize = readCodeSize;
27
27
  const getParam = (key, records) => {
28
- return records?.find((param) => param.key === key)?.value;
28
+ if (!records)
29
+ return undefined;
30
+ if (Array.isArray(records)) {
31
+ return records.find((param) => param.key === key)?.value;
32
+ }
33
+ return records[key];
29
34
  };
30
35
  // Attempt to infer the type of the value if it was a template reference
31
36
  const inferType = (value, wasTemplateRef) => {
@@ -73,7 +78,8 @@ const calcValue = (rawValue, ctx, iacVars) => {
73
78
  }
74
79
  if (containsMap?.length) {
75
80
  value = value.replace(/\$\{stages\.(\w+)}/g, (_, key) => {
76
- const stageValue = getParam(key, (0, lodash_1.get)(ctx.stages, `${ctx.stage}`));
81
+ const stageConfig = (0, lodash_1.get)(ctx.stages, `${ctx.stage}`, {});
82
+ const stageValue = getParam(key, stageConfig);
77
83
  if (!stageValue) {
78
84
  logger_1.logger.warn(lang_1.lang.__('STAGE_VARIABLE_NOT_FOUND', {
79
85
  key,
@@ -105,12 +105,22 @@ const transformFCResponse = (result) => {
105
105
  if (isBase64Encoded && typeof body === 'string') {
106
106
  body = Buffer.from(body, 'base64').toString('utf-8');
107
107
  }
108
+ // Only JSON-parse if the response Content-Type indicates JSON — otherwise pass through as-is.
109
+ // Aliyun API Gateway PASSTHROUGH mode sends raw body; si-local mirrors this behavior.
108
110
  if (typeof body === 'string') {
109
- try {
110
- body = JSON.parse(body);
111
- }
112
- catch {
113
- // If parsing fails, keep as string
111
+ const contentType = typeof headers === 'object' && headers
112
+ ? (Object.values(headers).find((v) => typeof v === 'string' && v.toLowerCase().includes('application/json')) ??
113
+ Object.keys(headers).find((k) => k.toLowerCase() === 'content-type' &&
114
+ typeof headers[k] === 'string' &&
115
+ headers[k].toLowerCase().includes('application/json')))
116
+ : undefined;
117
+ if (contentType || /^\s*[{[]/.test(body)) {
118
+ try {
119
+ body = JSON.parse(body);
120
+ }
121
+ catch {
122
+ // keep as string
123
+ }
114
124
  }
115
125
  }
116
126
  return { statusCode, headers, body };
@@ -64,12 +64,9 @@ const servLocal = async (handlers, iac) => {
64
64
  respondJson(res, 204, {});
65
65
  return;
66
66
  }
67
- // Raw responses (e.g., from bucket handler) include both Content-Type and Content-Length headers
68
- // and the body is already formatted as a string (not a JSON object)
69
- const isRawResponse = typeof outcome.body === 'string' &&
70
- outcome.headers?.['Content-Type'] &&
71
- outcome.headers?.['Content-Length'];
72
- if (isRawResponse) {
67
+ // Cloud API Gateway in PASSTHROUGH mode passes through all responses as-is.
68
+ // Si-local mirrors this by always using respondRaw for function responses.
69
+ if (typeof outcome.body === 'string' || Buffer.isBuffer(outcome.body)) {
73
70
  respondRaw(res, outcome.statusCode, outcome.body, outcome.headers);
74
71
  }
75
72
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
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",