@stylewx/publisher 0.2.0 → 0.2.2

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 (2) hide show
  1. package/README.md +52 -0
  2. package/package.json +24 -2
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @stylewx/publisher
2
+
3
+ 微信公众号草稿箱客户端:**只发草稿,不群发**。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm i @stylewx/publisher
9
+ ```
10
+
11
+ ## 用法
12
+
13
+ ```ts
14
+ import {
15
+ WeChatClient,
16
+ loadConfigFromEnv,
17
+ publishDraft,
18
+ relocateExternalImages,
19
+ } from '@stylewx/publisher'
20
+
21
+ const client = new WeChatClient(loadConfigFromEnv())
22
+
23
+ // 可选:把外链图片搬进微信素材库(正文外链图会被微信拦截)
24
+ const localHtml = await relocateExternalImages(html, client)
25
+
26
+ const result = await publishDraft(client, {
27
+ title: '文章标题',
28
+ html: localHtml,
29
+ })
30
+
31
+ console.log(result.media_id) // 草稿 media_id
32
+ ```
33
+
34
+ ## 凭据
35
+
36
+ 只从环境变量读取,不要在代码里硬编码:
37
+
38
+ | 变量 | 说明 |
39
+ | --- | --- |
40
+ | `WECHAT_APP_ID` | 公众号 AppID |
41
+ | `WECHAT_APP_SECRET` | 公众号 AppSecret |
42
+ | `WECHAT_API_BASE` | 可选,默认官方接口地址(便于走代理或自建网关) |
43
+
44
+ ## 附带能力
45
+
46
+ - `relocateExternalImages(html, client)` — 外链图片 → 微信素材库(实测 8 张外链图全部搬运成功,
47
+ 返回的内容内图片地址为 `mmbiz.qpic.cn`)
48
+ - `generateDefaultCover()` — 未提供封面时生成 900×383 的默认封面
49
+
50
+ ---
51
+
52
+ 属于 **[stylewx](https://github.com/wjunhere/stylewx)** —— 把 Markdown 排成微信公众号文章的工具链。MIT License.
package/package.json CHANGED
@@ -1,7 +1,26 @@
1
1
  {
2
2
  "name": "@stylewx/publisher",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "stylewx publisher: WeChat Official Account API wrapper (access_token, image upload, draft/add) + external-image relocation. Node-only by design.",
5
+ "keywords": [
6
+ "wechat",
7
+ "wechat-article",
8
+ "official-account",
9
+ "draft",
10
+ "publish",
11
+ "微信公众号"
12
+ ],
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "wjunhere",
16
+ "url": "https://github.com/wjunhere"
17
+ },
18
+ "homepage": "https://github.com/wjunhere/stylewx#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/wjunhere/stylewx.git",
22
+ "directory": "packages/publisher"
23
+ },
5
24
  "type": "module",
6
25
  "main": "./dist/index.js",
7
26
  "types": "./dist/index.d.ts",
@@ -14,7 +33,6 @@
14
33
  "files": [
15
34
  "dist"
16
35
  ],
17
- "sideEffects": false,
18
36
  "dependencies": {
19
37
  "rehype-parse": "^9.0.1",
20
38
  "rehype-stringify": "^10.0.1",
@@ -23,6 +41,10 @@
23
41
  "publishConfig": {
24
42
  "access": "public"
25
43
  },
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "sideEffects": false,
26
48
  "scripts": {
27
49
  "build": "tsc -p tsconfig.json",
28
50
  "test": "vitest run",