@lark-apaas/miaoda-cli 0.1.4-alpha.8b6506a → 0.1.4-alpha.9796712

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.batchSavePluginInstances = exports.LocalReleaseStatus = exports.getModernLastPublishedVersion = exports.getModernReleaseStatus = exports.createModernRelease = exports.updateLocalRelease = exports.createLocalRelease = exports.preRelease = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
3
+ exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.batchSavePluginInstances = exports.LocalReleaseStatus = exports.getModernLastPublishedVersion = exports.getModernReleaseStatus = exports.createModernRelease = exports.callbackStatic = exports.updateLocalRelease = exports.createLocalRelease = exports.preRelease = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
4
4
  var api_1 = require("./api");
5
5
  Object.defineProperty(exports, "createRelease", { enumerable: true, get: function () { return api_1.createRelease; } });
6
6
  Object.defineProperty(exports, "listPipelineInstances", { enumerable: true, get: function () { return api_1.listPipelineInstances; } });
@@ -10,6 +10,7 @@ var modern_1 = require("./modern");
10
10
  Object.defineProperty(exports, "preRelease", { enumerable: true, get: function () { return modern_1.preRelease; } });
11
11
  Object.defineProperty(exports, "createLocalRelease", { enumerable: true, get: function () { return modern_1.createLocalRelease; } });
12
12
  Object.defineProperty(exports, "updateLocalRelease", { enumerable: true, get: function () { return modern_1.updateLocalRelease; } });
13
+ Object.defineProperty(exports, "callbackStatic", { enumerable: true, get: function () { return modern_1.callbackStatic; } });
13
14
  Object.defineProperty(exports, "createModernRelease", { enumerable: true, get: function () { return modern_1.createRelease; } });
14
15
  Object.defineProperty(exports, "getModernReleaseStatus", { enumerable: true, get: function () { return modern_1.getReleaseStatus; } });
15
16
  Object.defineProperty(exports, "getModernLastPublishedVersion", { enumerable: true, get: function () { return modern_1.getLastPublishedVersion; } });
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.preRelease = preRelease;
14
14
  exports.createLocalRelease = createLocalRelease;
15
15
  exports.updateLocalRelease = updateLocalRelease;
16
+ exports.callbackStatic = callbackStatic;
16
17
  exports.createRelease = createRelease;
17
18
  exports.getReleaseStatus = getReleaseStatus;
18
19
  exports.getLastPublishedVersion = getLastPublishedVersion;
@@ -48,6 +49,13 @@ async function updateLocalRelease(req) {
48
49
  const url = `/v1/devops/app/${encodeURIComponent(appID)}/local_publish/update_release`;
49
50
  await (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to update local release'));
50
51
  }
52
+ // ── callbackStatic(PaaS Storage 静态资源上传完成回调) ──
53
+ /** POST /v1/storage/app/:appID/bucket/:bucketID/object/callbackStatic */
54
+ async function callbackStatic(req) {
55
+ const { appID, bucketID, uploadID } = req;
56
+ const url = `/v1/storage/app/${encodeURIComponent(appID)}/bucket/${encodeURIComponent(bucketID)}/object/callbackStatic`;
57
+ return (0, http_1.postInnerApi)(url, { uploadID }, envelopeOpts('Failed to callback static upload'));
58
+ }
51
59
  // ── release(远端部署,B / C 链路;本期不导出,类型骨架已就绪) ──
52
60
  /** POST /v1/devops/app/:appID/remote_publish/release */
53
61
  async function createRelease(req) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // plugin_instances batch_save 接口的请求 / 响应类型。
3
3
  //
4
- // 与 modern deploy 其它接口走的 lark.apaas.devops PSM 不同,
5
- // 本接口走 lark.apaas.studio_server,响应信封形态也不一样(BaseResp 而非 status_code)。
4
+ // 后端已统一到 InnerEnvelope(`{data, status_code, message}`),与 modern deploy
5
+ // 其它接口一致;旧的 BaseResp 形态已下线,类型也不再保留。
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,30 +1,22 @@
1
1
  "use strict";
2
2
  // studio_server 的 plugin_instances 批量保存接口。
3
- // 与 modern deploy 其余接口(走 devops PSM、InnerEnvelope)信封不同,
4
- // 这里走 studio_server PSM、BaseResp 信封,故自行解析。
3
+ //
4
+ // 后端已统一到 InnerEnvelope(`{data, status_code, message}`)信封;不再手撸
5
+ // 旧 BaseResp 解析,直接复用 utils/http.ts 的 postInnerApi,verbose 下也能拿到
6
+ // `→ POST` / `body:` / `resp:` 的完整日志。
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  exports.batchSavePluginInstances = batchSavePluginInstances;
7
9
  const http_1 = require("../../utils/http");
8
- const error_1 = require("../../utils/error");
9
10
  const URL_PATH = '/api/v1/studio/innerapi/plugin_instances/batch_save';
10
11
  /**
11
12
  * POST /api/v1/studio/innerapi/plugin_instances/batch_save
12
13
  *
13
14
  * 把发布版本的 capability 集合注册到 studio_server。
14
- * 失败时抛 AppError("DEPLOY_PLUGIN_BATCH_SAVE_FAILED"),带 BaseResp 错误信息。
15
+ * 失败时抛 AppError("DEPLOY_PLUGIN_BATCH_SAVE_FAILED"),错误信息来自 envelope.message。
15
16
  */
16
17
  async function batchSavePluginInstances(req) {
17
- const response = await (0, http_1.getHttpClient)().post(URL_PATH, req);
18
- if (!response.ok) {
19
- throw new error_1.HttpError(response.status, URL_PATH, `Failed to save plugin instances: ${String(response.status)} ${response.statusText}`);
20
- }
21
- const body = (await response.json());
22
- const baseResp = body.BaseResp;
23
- if (baseResp?.StatusCode !== 0) {
24
- const msg = baseResp?.StatusMessage ?? baseResp?.KStatusMessage ?? 'unknown error';
25
- const code = baseResp?.KStatusCode !== undefined && baseResp.KStatusCode !== ''
26
- ? baseResp.KStatusCode
27
- : String(baseResp?.StatusCode ?? 'unknown');
28
- throw new error_1.AppError('DEPLOY_PLUGIN_BATCH_SAVE_FAILED', `Failed to save plugin instances: status_code=${code} message=${msg}`);
29
- }
18
+ await (0, http_1.postInnerApi)(URL_PATH, req, {
19
+ errPrefix: 'Failed to save plugin instances',
20
+ defaultErrCode: 'DEPLOY_PLUGIN_BATCH_SAVE_FAILED',
21
+ });
30
22
  }
@@ -10,17 +10,18 @@ const node_path_1 = __importDefault(require("node:path"));
10
10
  const npm_pack_1 = require("../../../utils/npm-pack");
11
11
  const error_1 = require("../../../utils/error");
12
12
  const logger_1 = require("../../../utils/logger");
13
- /** 短名 → 包名映射。新增 stack 时改这里。 */
13
+ /** 短名 → 包名映射。新增 stack 时改这里。archType 由 template 包自报,CLI 不维护。 */
14
14
  exports.TEMPLATE_PACKAGE_BY_STACK = {
15
15
  'vite-react': '@lark-apaas/coding-template-vite-react',
16
16
  html: '@lark-apaas/coding-template-html',
17
17
  };
18
18
  exports.SUPPORTED_STACKS = Object.keys(exports.TEMPLATE_PACKAGE_BY_STACK);
19
- // template/ 内以下划线开头的占位文件名在渲染时改名(npm publish 会把 .gitignore 吞掉,
20
- // 模板里用 _gitignore 提交,渲染时再改回)。
19
+ // template/ 内以下划线开头的占位文件名在渲染时改名(npm publish 会把 .gitignore / .npmrc 吞掉,
20
+ // 模板里用 _gitignore / _npmrc 提交,渲染时再改回)。
21
21
  const RENAME_FILES = {
22
22
  _gitignore: '.gitignore',
23
23
  '_env.local': '.env.local',
24
+ _npmrc: '.npmrc',
24
25
  };
25
26
  function renderTemplate(opts) {
26
27
  const packageName = exports.TEMPLATE_PACKAGE_BY_STACK[opts.stack];
@@ -37,12 +38,13 @@ function renderTemplate(opts) {
37
38
  throw new error_1.AppError('TEMPLATE_INVALID', `包 ${packageName}@${fetched.version} 缺少 template/ 目录`);
38
39
  }
39
40
  const pkgJsonPath = node_path_1.default.join(fetched.extractDir, 'package.json');
40
- let archType = '';
41
+ let archType;
41
42
  if (node_fs_1.default.existsSync(pkgJsonPath)) {
42
43
  const pkgJson = JSON.parse(node_fs_1.default.readFileSync(pkgJsonPath, 'utf-8'));
43
- archType = pkgJson.miaodaTemplate?.archType ?? '';
44
+ archType = pkgJson.miaodaTemplate?.archType;
44
45
  }
45
- if (!archType) {
46
+ // 用显式 null/undefined/'' 判,避免把合法值 0 / false 当成"缺失"误抛
47
+ if (archType === undefined || archType === null || archType === '') {
46
48
  throw new error_1.AppError('TEMPLATE_INVALID', `包 ${packageName}@${fetched.version} 缺少 package.json.miaodaTemplate.archType`);
47
49
  }
48
50
  (0, logger_1.log)('init', `Rendering template to ${opts.targetDir}...`);
@@ -6,13 +6,14 @@ const error_1 = require("../../../../utils/error");
6
6
  const logger_1 = require("../../../../utils/logger");
7
7
  const protocol_1 = require("../protocol");
8
8
  /**
9
- * 给 CDN 前缀补 https:// 协议头:
9
+ * 给 RESOURCE_CDN_PREFIX 补 https:// 协议头:
10
10
  * - 已带 http:// 或 https:// → 原样返回
11
11
  * - 以 / 开头(绝对路径)→ 原样返回
12
12
  * - 不含 dot(看起来不像域名,比如纯路径 app_xxx/2)→ 原样返回
13
13
  * - 其它(典型:lf-xxx.bytetos.com/...)→ 前缀 https://
14
14
  *
15
15
  * template 的 build script 直接拿来当 vite base / asset URL 用,必须是合法 URL。
16
+ * STATIC_CDN_PREFIX 由 runtime 同域提供(相对路径),不走这里。
16
17
  */
17
18
  function ensureHttpsScheme(v) {
18
19
  if (/^https?:\/\//i.test(v))
@@ -28,17 +29,21 @@ function ensureHttpsScheme(v) {
28
29
  * MIAODA_APP_ID / MIAODA_VERSION / MIAODA_STACK
29
30
  * MIAODA_RESOURCE_CDN_PREFIX / MIAODA_STATIC_CDN_PREFIX
30
31
  *
31
- * CDN 前缀缺 scheme 时由 CLI 自动补 https://,template 不用关心。
32
+ * MIAODA_STATIC_CDN_PREFIX 取自 output_static_paas_storage_credential.downloadURLPrefix,
33
+ * 是 runtime 同域相对路径(例如 /app/<appId>/runtime/api/v1/storage/object/<bucket>/),
34
+ * 不补 https scheme,原样注入。顶层 static_cdn_prefix 不再下发。
35
+ *
32
36
  * build 失败抛 AppError(execSync 自身会 throw,捕获后包一层加错误码)。
33
37
  */
34
38
  function runBuild(opts) {
39
+ const staticCred = (0, protocol_1.parsePaasStorageCredential)((0, protocol_1.requireDataKey)(opts.data, protocol_1.DataKey.OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL), protocol_1.DataKey.OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL);
35
40
  const buildEnv = {
36
41
  ...process.env,
37
42
  MIAODA_APP_ID: opts.appId,
38
43
  MIAODA_VERSION: opts.version,
39
44
  MIAODA_STACK: opts.templateKey,
40
45
  MIAODA_RESOURCE_CDN_PREFIX: ensureHttpsScheme((0, protocol_1.requireDataKey)(opts.data, protocol_1.DataKey.RESOURCE_CDN_PREFIX)),
41
- MIAODA_STATIC_CDN_PREFIX: ensureHttpsScheme((0, protocol_1.requireDataKey)(opts.data, protocol_1.DataKey.STATIC_CDN_PREFIX)),
46
+ MIAODA_STATIC_CDN_PREFIX: staticCred.downloadURLPrefix,
42
47
  };
43
48
  (0, logger_1.log)('deploy', 'Building...');
44
49
  try {
@@ -8,21 +8,28 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_os_1 = __importDefault(require("node:os"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  const node_child_process_1 = require("node:child_process");
11
+ const index_1 = require("../../../../api/deploy/index");
11
12
  const error_1 = require("../../../../utils/error");
12
13
  const logger_1 = require("../../../../utils/logger");
13
14
  const constants_1 = require("../constants");
14
15
  const protocol_1 = require("../protocol");
15
16
  const UPLOAD_PLAN = [
16
- { dir: constants_1.OUTPUT_DIR, dataKey: protocol_1.DataKey.OUTPUT_TOS_UPLOAD_CREDENTIAL, required: true },
17
17
  {
18
+ kind: 'tos',
19
+ dir: constants_1.OUTPUT_DIR,
20
+ dataKey: protocol_1.DataKey.OUTPUT_TOS_UPLOAD_CREDENTIAL,
21
+ required: true,
22
+ },
23
+ {
24
+ kind: 'tos',
18
25
  dir: constants_1.OUTPUT_RESOURCE_DIR,
19
26
  dataKey: protocol_1.DataKey.OUTPUT_RESOURCE_TOS_UPLOAD_CREDENTIAL,
20
27
  required: false,
21
28
  },
22
29
  {
30
+ kind: 'paas_storage',
23
31
  dir: constants_1.OUTPUT_STATIC_DIR,
24
- dataKey: protocol_1.DataKey.OUTPUT_STATIC_TOS_UPLOAD_CREDENTIAL,
25
- required: false,
32
+ dataKey: protocol_1.DataKey.OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL,
26
33
  },
27
34
  ];
28
35
  function resolveTosutilPath() {
@@ -36,33 +43,28 @@ function resolveTosutilPath() {
36
43
  }
37
44
  throw new error_1.AppError('DEPLOY_TOSUTIL_MISSING', 'tosutil is not installed or not in PATH. modern deploy requires sandbox preinstalled tosutil.');
38
45
  }
39
- /** 把 data 里的凭证字段 JSON.parse 出来;非法 JSON / 缺字段都抛 AppError */
40
- function parseCredential(raw, dataKey) {
41
- let parsed;
42
- try {
43
- parsed = JSON.parse(raw);
44
- }
45
- catch (err) {
46
- throw new error_1.AppError('DEPLOY_CRED_INVALID_JSON', `preRelease.data["${dataKey}"] is not valid JSON: ${err.message}`);
47
- }
48
- if (typeof parsed !== 'object' || parsed === null) {
49
- throw new error_1.AppError('DEPLOY_CRED_INVALID_JSON', `preRelease.data["${dataKey}"] is not an object`);
50
- }
51
- const c = parsed;
52
- const required = [
53
- 'accessKeyID',
54
- 'secretAccessKey',
55
- 'sessionToken',
56
- 'endpoint',
57
- 'region',
58
- 'bucket',
59
- 'prefix',
60
- ];
61
- const missing = required.filter((k) => typeof c[k] !== 'string' || c[k] === '');
62
- if (missing.length > 0) {
63
- throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"] credential missing fields: ${missing.join(', ')}`);
64
- }
65
- return c;
46
+ function tosutilUploadFromTos(cred) {
47
+ return {
48
+ accessKeyID: cred.accessKeyID,
49
+ secretAccessKey: cred.secretAccessKey,
50
+ sessionToken: cred.sessionToken,
51
+ endpoint: cred.endpoint,
52
+ region: cred.region,
53
+ bucket: cred.bucket,
54
+ prefix: cred.prefix,
55
+ };
56
+ }
57
+ function tosutilUploadFromPaasStorage(cred, dataKey) {
58
+ const { bucket, prefix } = (0, protocol_1.parseTosUploadPrefix)(cred.uploadPrefix, dataKey);
59
+ return {
60
+ accessKeyID: cred.accessKeyID,
61
+ secretAccessKey: cred.secretAccessKey,
62
+ sessionToken: cred.sessionToken,
63
+ endpoint: cred.endpoint,
64
+ region: cred.region,
65
+ bucket,
66
+ prefix,
67
+ };
66
68
  }
67
69
  /**
68
70
  * 写一个 tosutil 临时 config 文件,注入 STS 凭证 + endpoint + region。
@@ -164,42 +166,81 @@ function uploadDirWithCredential(tosutilPath, sourceDir, cred, label) {
164
166
  throw new error_1.AppError('DEPLOY_UPLOAD_EMPTY', `Upload failed: 0 files uploaded. source=${sourceDir}. Check tosutil credentials and bucket permissions.`);
165
167
  }
166
168
  }
169
+ function uploadTosTarget(tosutilPath, target, localPath, data) {
170
+ const credRaw = target.required
171
+ ? (0, protocol_1.requireDataKey)(data, target.dataKey)
172
+ : (0, protocol_1.optionalDataKey)(data, target.dataKey);
173
+ if (credRaw === undefined) {
174
+ (0, logger_1.debug)(`upload: ${target.dir} exists but no credential configured, skipping`);
175
+ return false;
176
+ }
177
+ const cred = (0, protocol_1.parseTosUploadCredential)(credRaw, target.dataKey);
178
+ (0, logger_1.log)('deploy', `Uploading ${target.dir}...`);
179
+ uploadDirWithCredential(tosutilPath, localPath, tosutilUploadFromTos(cred), target.dir);
180
+ return true;
181
+ }
182
+ function uploadPaasStorageTarget(tosutilPath, target, localPath, data) {
183
+ // 空目录:直接跳过;callbackStatic 也不能调,否则会让后端把"未发生的上传"
184
+ // 误以为已完成。凭证本身 build 阶段已经消费过 downloadURLPrefix,这里不重复要求。
185
+ if (node_fs_1.default.readdirSync(localPath).length === 0) {
186
+ (0, logger_1.debug)(`upload: ${target.dir} is empty, skipping`);
187
+ return undefined;
188
+ }
189
+ const cred = (0, protocol_1.parsePaasStorageCredential)((0, protocol_1.requireDataKey)(data, target.dataKey), target.dataKey);
190
+ (0, logger_1.log)('deploy', `Uploading ${target.dir}...`);
191
+ uploadDirWithCredential(tosutilPath, localPath, tosutilUploadFromPaasStorage(cred, target.dataKey), target.dir);
192
+ return cred;
193
+ }
167
194
  /**
168
- * 上传三类产物。每类的凭证来自 preRelease.data 中对应 *_tos_upload_credential 字段
169
- * (JSON.stringify 的 TosUploadCredential 对象):
195
+ * 上传三类产物。output / output_resource 走 TOS STS 凭证;output_static 走 PaaS Storage
196
+ * 凭证(uploadPrefix 解出 tosutil cp 目的,上传完后再调 callbackStatic 把 uploadID
197
+ * 提交给后端核销):
170
198
  * - dist/output (必传) → OUTPUT_TOS_UPLOAD_CREDENTIAL
171
199
  * - dist/output_resource (可选) → OUTPUT_RESOURCE_TOS_UPLOAD_CREDENTIAL
172
- * - dist/output_static (可选) → OUTPUT_STATIC_TOS_UPLOAD_CREDENTIAL
200
+ * - dist/output_static (可选) → OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL + callbackStatic
173
201
  *
174
202
  * 目录不存在的可选项跳过;output 不存在或凭证缺失抛错。
175
203
  */
176
- function uploadArtifacts(opts) {
204
+ async function uploadArtifacts(opts) {
177
205
  const tosutilPath = resolveTosutilPath();
178
206
  const distDir = node_path_1.default.join(opts.projectDir, constants_1.DIST_DIR);
179
- let uploaded = 0;
207
+ const outcome = { uploaded: 0 };
180
208
  for (const target of UPLOAD_PLAN) {
181
209
  const localPath = node_path_1.default.join(distDir, target.dir);
182
210
  const exists = node_fs_1.default.existsSync(localPath);
183
- if (!exists) {
184
- if (target.required) {
185
- throw new error_1.AppError('DEPLOY_NO_BUILD_OUTPUT', `Required directory missing: ${constants_1.DIST_DIR}/${target.dir}`);
211
+ if (target.kind === 'tos') {
212
+ if (!exists) {
213
+ if (target.required) {
214
+ throw new error_1.AppError('DEPLOY_NO_BUILD_OUTPUT', `Required directory missing: ${constants_1.DIST_DIR}/${target.dir}`);
215
+ }
216
+ (0, logger_1.debug)(`upload: dir not present, skipping ${target.dir}`);
217
+ continue;
218
+ }
219
+ if (uploadTosTarget(tosutilPath, target, localPath, opts.data)) {
220
+ outcome.uploaded++;
186
221
  }
187
- (0, logger_1.debug)(`upload: dir not present, skipping ${target.dir}`);
188
222
  continue;
189
223
  }
190
- const credRaw = target.required
191
- ? (0, protocol_1.requireDataKey)(opts.data, target.dataKey)
192
- : (0, protocol_1.optionalDataKey)(opts.data, target.dataKey);
193
- if (credRaw === undefined) {
194
- (0, logger_1.debug)(`upload: ${target.dir} exists but no credential configured, skipping`);
224
+ // PaaS Storage 分支
225
+ if (!exists) {
226
+ (0, logger_1.debug)(`upload: dir not present, skipping ${target.dir}`);
195
227
  continue;
196
228
  }
197
- const cred = parseCredential(credRaw, target.dataKey);
198
- (0, logger_1.log)('deploy', `Uploading ${target.dir}...`);
199
- uploadDirWithCredential(tosutilPath, localPath, cred, target.dir);
200
- uploaded++;
229
+ const cred = uploadPaasStorageTarget(tosutilPath, target, localPath, opts.data);
230
+ if (cred) {
231
+ outcome.staticUploaded = cred;
232
+ outcome.uploaded++;
233
+ }
201
234
  }
202
- if (uploaded === 0) {
235
+ if (outcome.uploaded === 0) {
203
236
  throw new error_1.AppError('DEPLOY_UPLOAD_EMPTY', 'No artifacts uploaded — check build output.');
204
237
  }
238
+ if (outcome.staticUploaded) {
239
+ (0, logger_1.log)('deploy', 'Callbacking static upload...');
240
+ await (0, index_1.callbackStatic)({
241
+ appID: opts.appId,
242
+ bucketID: outcome.staticUploaded.bucketID,
243
+ uploadID: outcome.staticUploaded.uploadID,
244
+ });
245
+ }
205
246
  }
@@ -46,7 +46,7 @@ async function localBuildLocalPublishPipeline(opts) {
46
46
  const release = await (0, index_1.createLocalRelease)(ctx.appId, pre.version);
47
47
  try {
48
48
  (0, logger_1.log)('deploy', 'Uploading artifacts...');
49
- (0, index_1.uploadArtifacts)({ projectDir: ctx.projectDir, data });
49
+ await (0, index_1.uploadArtifacts)({ projectDir: ctx.projectDir, appId: ctx.appId, data });
50
50
  const saveResult = await (0, index_1.savePluginInstances)({
51
51
  projectDir: ctx.projectDir,
52
52
  appId: ctx.appId,
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataKey = void 0;
4
4
  exports.requireDataKey = requireDataKey;
5
5
  exports.optionalDataKey = optionalDataKey;
6
+ exports.parseTosUploadCredential = parseTosUploadCredential;
7
+ exports.parsePaasStorageCredential = parsePaasStorageCredential;
8
+ exports.parseTosUploadPrefix = parseTosUploadPrefix;
6
9
  const error_1 = require("../../../utils/error");
7
10
  /**
8
11
  * modern deploy 对外协议常量集中地(SSOT)。
@@ -15,9 +18,7 @@ exports.DataKey = {
15
18
  // ── CDN 前缀(构建期注入到 build env,用于客户端资源访问) ──
16
19
  /** dist/output_resource 对应的 CDN 域名前缀 */
17
20
  RESOURCE_CDN_PREFIX: 'resource_cdn_prefix',
18
- /** dist/output_static 对应的 CDN 域名前缀 */
19
- STATIC_CDN_PREFIX: 'static_cdn_prefix',
20
- // ── TOS 上传凭证(与三个产物目录一一对应,value 为 JSON.stringify 的凭证对象) ──
21
+ // ── TOS 上传凭证(output / output_resource 两条线,value 为 JSON.stringify 的凭证对象) ──
21
22
  // 凭证对象形态(camelCase):
22
23
  // { accessKeyID, secretAccessKey, sessionToken, endpoint, region, bucket, prefix }
23
24
  // CLI 端 JSON.parse 后写 tosutil 临时 config,cp 到 tos://bucket/prefix。
@@ -25,8 +26,13 @@ exports.DataKey = {
25
26
  OUTPUT_TOS_UPLOAD_CREDENTIAL: 'output_tos_upload_credential',
26
27
  /** dist/output_resource 上传凭证(仅当目录存在时使用) */
27
28
  OUTPUT_RESOURCE_TOS_UPLOAD_CREDENTIAL: 'output_resource_tos_upload_credential',
29
+ // ── PaaS Storage 静态资源凭证(dist/output_static 专用) ──
30
+ // 形态:JSON.stringify 后的 PaasStorageCredential(见下方 interface)。
31
+ // 上传走 tosutil(从 uploadPrefix 解析出 bucket/prefix);上传完成后再调
32
+ // callbackStatic(appID, bucketID, uploadID) 把本次上传核销给后端;
33
+ // downloadURLPrefix 替代原 static_cdn_prefix 注入 build env。
28
34
  /** dist/output_static 上传凭证(仅当目录存在时使用) */
29
- OUTPUT_STATIC_TOS_UPLOAD_CREDENTIAL: 'output_static_tos_upload_credential',
35
+ OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL: 'output_static_paas_storage_credential',
30
36
  };
31
37
  /** 取必传 key,缺失抛 AppError(带 key 名,便于后端 tcc 配置排查) */
32
38
  function requireDataKey(data, key) {
@@ -41,3 +47,76 @@ function optionalDataKey(data, key) {
41
47
  const v = data[key];
42
48
  return v === undefined || v === '' ? undefined : v;
43
49
  }
50
+ const TOS_CREDENTIAL_REQUIRED_FIELDS = [
51
+ 'accessKeyID',
52
+ 'secretAccessKey',
53
+ 'sessionToken',
54
+ 'endpoint',
55
+ 'region',
56
+ 'bucket',
57
+ 'prefix',
58
+ ];
59
+ const PAAS_STORAGE_CREDENTIAL_REQUIRED_FIELDS = [
60
+ 'accessKeyID',
61
+ 'secretAccessKey',
62
+ 'sessionToken',
63
+ 'endpoint',
64
+ 'region',
65
+ 'uploadPrefix',
66
+ 'downloadURLPrefix',
67
+ 'uploadID',
68
+ 'bucketID',
69
+ ];
70
+ function parseCredentialObject(raw, dataKey) {
71
+ let parsed;
72
+ try {
73
+ parsed = JSON.parse(raw);
74
+ }
75
+ catch (err) {
76
+ throw new error_1.AppError('DEPLOY_CRED_INVALID_JSON', `preRelease.data["${dataKey}"] is not valid JSON: ${err.message}`);
77
+ }
78
+ if (typeof parsed !== 'object' || parsed === null) {
79
+ throw new error_1.AppError('DEPLOY_CRED_INVALID_JSON', `preRelease.data["${dataKey}"] is not an object`);
80
+ }
81
+ return parsed;
82
+ }
83
+ function assertStringFields(obj, required, dataKey) {
84
+ const missing = required.filter((k) => {
85
+ const v = obj[k];
86
+ return typeof v !== 'string' || v === '';
87
+ });
88
+ if (missing.length > 0) {
89
+ throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"] credential missing fields: ${missing.join(', ')}`);
90
+ }
91
+ return obj;
92
+ }
93
+ /** JSON.parse + 字段完整性校验:output / output_resource 凭证 */
94
+ function parseTosUploadCredential(raw, dataKey) {
95
+ const obj = parseCredentialObject(raw, dataKey);
96
+ return assertStringFields(obj, TOS_CREDENTIAL_REQUIRED_FIELDS, dataKey);
97
+ }
98
+ /** JSON.parse + 字段完整性校验:output_static PaaS Storage 凭证 */
99
+ function parsePaasStorageCredential(raw, dataKey) {
100
+ const obj = parseCredentialObject(raw, dataKey);
101
+ return assertStringFields(obj, PAAS_STORAGE_CREDENTIAL_REQUIRED_FIELDS, dataKey);
102
+ }
103
+ /**
104
+ * 解析 `tos://<storage-bucket>/<segments...>/` 形态的 uploadPrefix。
105
+ * 返回的 bucket 是 tosutil cp 视角的 TOS 物理 bucket(uploadPrefix 第一段),
106
+ * prefix 是其余路径(不含开头斜杠,保留可能存在的尾部斜杠以贴合 tosutil 习惯)。
107
+ *
108
+ * 注意:这里返回的 bucket 与 PaasStorageCredential.bucketID 不是同一个概念
109
+ * (bucketID 是 PaaS Storage 逻辑 bucket,给 callbackStatic 用)。
110
+ */
111
+ function parseTosUploadPrefix(uploadPrefix, dataKey) {
112
+ const match = /^tos:\/\/([^/]+)\/(.*)$/.exec(uploadPrefix);
113
+ if (!match) {
114
+ throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"].uploadPrefix must look like "tos://<bucket>/<prefix>/", got: ${uploadPrefix}`);
115
+ }
116
+ const bucket = match[1];
117
+ const prefix = match[2];
118
+ if (bucket === '' || prefix === '') {
119
+ throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"].uploadPrefix missing bucket or prefix segment: ${uploadPrefix}`);
120
+ }
121
+ return { bucket, prefix };
122
+ }
@@ -1,29 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveTemplateKey = resolveTemplateKey;
4
- const error_1 = require("../../../utils/error");
5
4
  /**
6
5
  * 本地 stack 短名 → 后端发布模板 key 的映射。
7
6
  *
8
- * .spark/meta.json.stack 存的是脚手架模板短名(vite-react / vue-react / html ...),
7
+ * .spark/meta.json.stack 存的是脚手架模板短名(vite-react / html ...),
9
8
  * 而服务端 preRelease 接受的 templateKey 是"部署类别"维度,由后端 tcc 注册。
10
- * 同一类别的多个脚手架共享一个部署 key(典型:所有纯前端 stack → client_local_deploy)。
11
- *
12
- * 加新 stack:在表里加一行;新增类别同步跟后端 tcc 配置对齐。
9
+ * 当前所有支持的 stack 都属于纯前端类别,默认映射到 client_local_deploy;
10
+ * 未来出现需要走别的 templateKey 的 stack,再在表里加一行覆盖默认。
13
11
  */
12
+ const DEFAULT_TEMPLATE_KEY = 'client_local_deploy';
14
13
  const TEMPLATE_KEY_MAP = {
15
- 'vite-react': 'client_local_deploy',
16
- 'vue-react': 'client_local_deploy',
14
+ 'vite-react': DEFAULT_TEMPLATE_KEY,
15
+ html: DEFAULT_TEMPLATE_KEY,
17
16
  };
18
17
  /**
19
- * 把本地 stack 短名映射到后端 templateKey。未配置的 stack 抛 AppError,
20
- * 避免拿原始短名直接打过去导致后端报"empty"或"出错了"等含糊错误。
18
+ * 把本地 stack 短名映射到后端 templateKey;未配置的 stack 走默认 client_local_deploy。
21
19
  */
22
20
  function resolveTemplateKey(template) {
23
- const key = TEMPLATE_KEY_MAP[template];
24
- if (key === undefined) {
25
- throw new error_1.AppError('DEPLOY_TEMPLATE_KEY_UNMAPPED', `Template "${template}" has no mapping to backend templateKey. ` +
26
- `Known: ${Object.keys(TEMPLATE_KEY_MAP).join(', ')}`);
27
- }
28
- return key;
21
+ return TEMPLATE_KEY_MAP[template] ?? DEFAULT_TEMPLATE_KEY;
29
22
  }
@@ -7,7 +7,7 @@ exports.readSkillsStatus = readSkillsStatus;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  /**
10
- * 扫描 <targetDir>/.agent/steering/<stack>/,给出"当前装了什么"的快照。
10
+ * 扫描 <targetDir>/.agent/skills/steering/<stack>/,给出"当前装了什么"的快照。
11
11
  * 不联网、不解析任何 SKILL.md 内容;只列目录名 + tech.md 是否在。
12
12
  *
13
13
  * stack 缺省(meta.json 缺 stack)时直接返回 present=false,
@@ -17,7 +17,7 @@ function readSkillsStatus(opts) {
17
17
  if (opts.stack === undefined || opts.stack === '') {
18
18
  return { present: false, skills: [], techSynced: false };
19
19
  }
20
- const root = node_path_1.default.join(opts.targetDir, '.agent', 'steering', opts.stack);
20
+ const root = node_path_1.default.join(opts.targetDir, '.agent', 'skills', 'steering', opts.stack);
21
21
  if (!node_fs_1.default.existsSync(root)) {
22
22
  return { present: false, skills: [], techSynced: false };
23
23
  }
@@ -27,9 +27,10 @@ function syncCodingSteering(opts) {
27
27
  const steeringRoot = node_path_1.default.join(fetched.extractDir, 'steering');
28
28
  const stackDir = node_path_1.default.join(steeringRoot, opts.stack);
29
29
  const commonSkillsDir = node_path_1.default.join(steeringRoot, '_common', 'skills');
30
- // steering 落到 .agent/steering/<stack>/,让同一 .agent/ 下可以并存多 stack(虽然
31
- // 当前一个项目只有一个 stack,但保持命名空间清晰,避免与其它 steering 生产方撞名)。
32
- const dstRoot = node_path_1.default.join(opts.targetDir, '.agent', 'steering', opts.stack);
30
+ // steering 落到 .agent/skills/steering/<stack>/。.agent/skills/ 是 agent skills 的
31
+ // 公共容器,steering 是其中一个 producer,<stack> 再做命名空间隔离。内部仍保留
32
+ // 包内 steering/<stack>/skills/ 的结构,便于按"包内子目录 → 本地子目录"一一对应排查。
33
+ const dstRoot = node_path_1.default.join(opts.targetDir, '.agent', 'skills', 'steering', opts.stack);
33
34
  const dstSkillsDir = node_path_1.default.join(dstRoot, 'skills');
34
35
  node_fs_1.default.mkdirSync(dstSkillsDir, { recursive: true });
35
36
  let techSynced = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-cli",
3
- "version": "0.1.4-alpha.8b6506a",
3
+ "version": "0.1.4-alpha.9796712",
4
4
  "description": "Miaoda 平台命令行工具,面向 Agent 调用",
5
5
  "type": "commonjs",
6
6
  "bin": {