@iflyrpa/actions 4.0.9 → 4.1.0-beta.0

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.
@@ -0,0 +1,41 @@
1
+ import type { ResponseData } from "@iflyrpa/share";
2
+ /**
3
+ * 用户可见的错误文案。
4
+ *
5
+ * 约定:凡是会进入 ResponseData.message(前端直接展示)的文案都从这里取,
6
+ * 不要把 err.message / error.code / 文件路径等技术细节拼进去 —— 那些信息
7
+ * 放 logger 与飞书告警里,用户侧只保留「看得懂 + 知道下一步做什么」的文案。
8
+ */
9
+ export declare const USER_MESSAGE: {
10
+ readonly PROXY_UNAVAILABLE: "代理暂时不可用,请稍后重试或使用本地IP";
11
+ readonly NETWORK_ERROR: "网络异常,请稍后重试";
12
+ readonly SYSTEM_ERROR: "系统异常,请稍后重试或联系客服";
13
+ readonly PUBLISH_NETWORK: "发布失败,网络不稳定,请稍后重试";
14
+ readonly DOUYIN_ACCOUNT_FETCH_FAILED: "抖音数据获取失败,请稍后重试";
15
+ readonly SHIPINHAO_ACCOUNT_FETCH_FAILED: "视频号数据获取失败,请稍后重试";
16
+ readonly DOUYIN_POST_FETCH_FAILED: "抖音作品数据获取失败,请稍后重试";
17
+ readonly SHIPINHAO_POST_FETCH_FAILED: "视频号作品数据获取失败,请稍后重试";
18
+ readonly BJH_POST_FETCH_FAILED: "百家号作品数据获取失败,请稍后重试";
19
+ readonly TT_POST_FETCH_FAILED: "头条号作品数据获取失败,请稍后重试";
20
+ readonly QRCODE_FETCH_FAILED: "认证二维码获取失败,请稍后重试";
21
+ readonly IMAGE_UPLOAD_FAILED: "图片上传失败,请稍后重试或联系客服";
22
+ };
23
+ /** 发布错误分类:category 只用于日志辨识,userMessage 才是用户可见文案 */
24
+ export interface PublishErrorClassification {
25
+ category: "代理错误" | "网络错误";
26
+ userMessage: string;
27
+ }
28
+ /**
29
+ * 对发布接口抛出的错误做分类,决定是「直接返回用户文案并终止」还是「交回 RPA 兜底」。
30
+ *
31
+ * 只拦代理/网络类错误 —— 这类错误重试耗尽后 RPA 兜底同样连不上,直接返回更快。
32
+ * 返回 null 表示交回调用方 `throw error`,由上层 executeAction 走 RPA 兜底。
33
+ *
34
+ * 刻意不拦风控(403/461/471)与参数(400/422)错误:executeAction(utils/index.ts:257)
35
+ * 只在 code 为 0 或 414 时终止,抛异常则继续执行下一个 action,
36
+ * 因此这两类错误抛出后能进 RPA 兜底 —— 走浏览器自动化,用户完成验证后仍有机会发布成功。
37
+ * 拦下来会掉掉这条补救路径,所以维持抛出。
38
+ *
39
+ * 注意 401 无需单列:http.ts 的响应拦截器已把 401 归一为 414(避免触发绘文平台鉴权逻辑)。
40
+ */
41
+ export declare function classifyPublishError(handledError: ResponseData): PublishErrorClassification | null;
@@ -0,0 +1,27 @@
1
+ export type FeishuAlarmLevel = "warning" | "alarm";
2
+ export type FeishuAlarmSource = "http" | "proxy";
3
+ export interface FeishuAlarmReport {
4
+ /** alarm 会额外 @所有人,warning 只发消息 */
5
+ level: FeishuAlarmLevel;
6
+ /** 业务标识:xiaohongshu / douyin / weixin ... */
7
+ platform: string;
8
+ /** 告警来源模块 */
9
+ source: FeishuAlarmSource;
10
+ /** 出错阶段,如 "POST /api/sns/web/v1/feed" */
11
+ stage: string;
12
+ /** 错误类型,如 HTTP_403 / ECONNRESET / PROXY_UNAVAILABLE */
13
+ errorType: string;
14
+ /** 接口错误码 */
15
+ code?: string | number;
16
+ /** 错误信息 */
17
+ msg?: string;
18
+ /** 请求地址 */
19
+ url?: string;
20
+ /** 消息标题,默认「RPA异常」 */
21
+ title?: string;
22
+ }
23
+ /**
24
+ * 上报错误到飞书群,失败静默:告警链路不能影响主流程。
25
+ * 同一 platform + source + errorType + code 组合在 60s 内只发一条。
26
+ */
27
+ export declare const reportFeishuAlarm: (report: FeishuAlarmReport) => void;
@@ -14,5 +14,12 @@ export declare class Http {
14
14
  retries?: number;
15
15
  retryDelay?: number;
16
16
  timeout?: number;
17
+ onUploadProgress?: (progressEvent: any) => void;
18
+ /**
19
+ * 外部取消信号(用于用户主动取消上传等场景)。
20
+ * 注意:不能直接用 config.signal —— 下面会用内部 AbortController 覆盖它做超时兜底,
21
+ * 所以外部信号必须在这里传入,由内部 controller 代理转发。
22
+ */
23
+ signal?: AbortSignal;
17
24
  }): Promise<T>;
18
25
  }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 图片验证选项
3
+ */
4
+ export interface ImageValidationOptions {
5
+ /** 最大文件大小(字节),默认不限制 */
6
+ maxSize?: number;
7
+ /** 允许的文件扩展名(小写,包含点号),如 ['.jpg', '.png'] */
8
+ allowedFormats?: readonly string[];
9
+ /** 最小宽度(像素) */
10
+ minWidth?: number;
11
+ /** 最大宽度(像素) */
12
+ maxWidth?: number;
13
+ /** 最小高度(像素) */
14
+ minHeight?: number;
15
+ /** 最大高度(像素) */
16
+ maxHeight?: number;
17
+ }
18
+ /**
19
+ * 图片验证错误
20
+ */
21
+ export declare class ImageValidationError extends Error {
22
+ code: number;
23
+ data: string;
24
+ constructor(message: string, code?: number, data?: string);
25
+ }
26
+ /**
27
+ * 验证图片文件
28
+ * @param filePath 图片文件路径
29
+ * @param options 验证选项
30
+ * @param platformName 平台名称,用于错误提示
31
+ * @throws {ImageValidationError} 当验证失败时抛出错误
32
+ */
33
+ export declare function validateImageFile(filePath: string, options: ImageValidationOptions, platformName: string): void;
34
+ /**
35
+ * 各平台图片限制预设配置
36
+ */
37
+ export declare const PlatformImageLimits: {
38
+ /** 百家号:5MB,仅支持 jpg、png */
39
+ readonly baijiahao: {
40
+ readonly maxSize: number;
41
+ readonly allowedFormats: readonly [".jpg", ".jpeg", ".png"];
42
+ };
43
+ /** 视频号:20MB */
44
+ readonly shipinhao: {
45
+ readonly maxSize: number;
46
+ };
47
+ /** 头条号:20MB,推荐 jpg、png 格式 */
48
+ readonly toutiao: {
49
+ readonly maxSize: number;
50
+ readonly allowedFormats: readonly [".jpg", ".jpeg", ".png"];
51
+ };
52
+ /** 抖音:50MB */
53
+ readonly douyin: {
54
+ readonly maxSize: number;
55
+ };
56
+ /** 小红书:32MB,支持多种格式 */
57
+ readonly xiaohongshu: {
58
+ readonly maxSize: number;
59
+ readonly allowedFormats: readonly [".jpg", ".jpeg", ".png", ".gif"];
60
+ };
61
+ };
62
+ /**
63
+ * 使用预设配置验证图片
64
+ * @param filePath 图片文件路径
65
+ * @param platform 平台名称
66
+ */
67
+ export declare function validateImageByPlatform(filePath: string, platform: keyof typeof PlatformImageLimits): void;
@@ -0,0 +1,31 @@
1
+ import { Http } from "../http";
2
+ /**
3
+ * 视频号上传认证信息
4
+ *
5
+ * 说明:本文件的两个接口调用逻辑从 actions/shipinhaoPublish/mock.ts 抽取而来,
6
+ * 该流程已在图文发布链路中实测可用,视频上传复用同一套认证。
7
+ */
8
+ export interface ShipinhaoUploadAuth {
9
+ /** 微信号数字 uin,上传接口 X-Arguments 中的 weixinnum */
10
+ uin: number;
11
+ /** 上传接口 Authorization 头 */
12
+ authKey: string;
13
+ /** finderUsername,发布接口 _log_finder_id 使用 */
14
+ finderUsername: string;
15
+ /** 视频 filetype(服务端下发,实测 20302) */
16
+ videoFileType: number;
17
+ /** 图片/封面 filetype(服务端下发,实测 20304) */
18
+ pictureFileType: number;
19
+ }
20
+ /** 认证失败时抛出,携带平台错误码便于上层归类 */
21
+ export declare class ShipinhaoAuthError extends Error {
22
+ readonly errCode: number;
23
+ constructor(message: string, errCode: number);
24
+ }
25
+ /**
26
+ * 获取视频号上传所需的认证信息
27
+ *
28
+ * @param cookies cookie 字符串(`name=value; name=value` 形式)
29
+ * @param http Http 实例(不走代理即可,认证接口对代理无要求)
30
+ */
31
+ export declare function getShipinhaoUploadAuth(cookies: string, http: Http): Promise<ShipinhaoUploadAuth>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iflyrpa/actions",
3
- "version": "4.0.9",
3
+ "version": "4.1.0-beta.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",