@perk-net/perk-pushplus-sdk 1.1.1 → 1.2.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.
- package/README.md +28 -1
- package/dist/index.cjs +244 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +296 -1
- package/dist/index.d.ts +296 -1
- package/dist/index.global.js +244 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +238 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/doc-api.ts +77 -0
- package/src/api/excel-api.ts +114 -0
- package/src/api/form-api.ts +92 -0
- package/src/client.ts +9 -0
- package/src/config.ts +1 -1
- package/src/enums.ts +37 -0
- package/src/index.ts +24 -0
- package/src/models.ts +182 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- **同时支持 Node.js 与浏览器**:Node.js 18+ 使用内置 `fetch`,浏览器使用原生 `fetch`,无运行时依赖。
|
|
6
6
|
- **三种产物**:CommonJS (`.cjs`) + ESModule (`.js`) + 浏览器 IIFE (`.global.js`),可通过 npm / `<script>` 直接加载。
|
|
7
7
|
- **完整 TypeScript 类型**:所有请求 / 响应 / 枚举 / 回调全部带类型声明。
|
|
8
|
-
- **全部开放接口**:用户、消息、消息 token、群组、群组用户、好友、webhook、渠道、ClawBot、功能设置、预处理、图片服务(含一键上传到 PushPlus
|
|
8
|
+
- **全部开放接口**:用户、消息、消息 token、群组、群组用户、好友、webhook、渠道、ClawBot、功能设置、预处理、图片服务(含一键上传到 PushPlus 图床)、push 表单、push 文档、push 表格。
|
|
9
9
|
- **AccessKey 自动管理**:缓存 + 过期前自动刷新;`code=401` 自动刷新并重试一次。
|
|
10
10
|
- **本地限流守卫**:命中 `code=900` 后按 token 短路同 token 后续发送,避免被服务端长期封禁。
|
|
11
11
|
- **Builder 链式 API**:与 Java/Python SDK 风格保持一致。
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
> 接口文档:
|
|
15
15
|
> - 消息接口:<https://www.pushplus.plus/doc/guide/api.html>
|
|
16
16
|
> - 开放接口:<https://www.pushplus.plus/doc/guide/openApi.html>
|
|
17
|
+
> - push 表单:<https://www.pushplus.plus/doc/ecosystem/form/>
|
|
18
|
+
> - push 文档:<https://www.pushplus.plus/doc/ecosystem/doc/>
|
|
19
|
+
> - push 表格:<https://www.pushplus.plus/doc/ecosystem/sheet/>
|
|
17
20
|
|
|
18
21
|
## 安装
|
|
19
22
|
|
|
@@ -182,6 +185,30 @@ const uploaded = await client.image.uploadBytes(bytes, { fileName: 'logo.png' })
|
|
|
182
185
|
console.log(uploaded.url); // 直接拿到可访问的图片 URL
|
|
183
186
|
const imgs = await client.image.list({ current: 1, pageSize: 10 });
|
|
184
187
|
await client.image.delete(imgs.list[0].id);
|
|
188
|
+
|
|
189
|
+
// push 表单
|
|
190
|
+
const form = await client.form.create('用户满意度调查');
|
|
191
|
+
await client.form.save({
|
|
192
|
+
id: form.id!,
|
|
193
|
+
title: '用户满意度调查',
|
|
194
|
+
items: [{ id: 'q_name', type: 'input', label: '您的姓名', required: true }],
|
|
195
|
+
});
|
|
196
|
+
const published = await client.form.publish(form.id!);
|
|
197
|
+
console.log(published.fillUrl);
|
|
198
|
+
|
|
199
|
+
// push 文档
|
|
200
|
+
const doc = await client.doc.create('本周工作同步');
|
|
201
|
+
await client.doc.saveContent(doc.docCode!, '<h1>本周工作同步</h1><p>需求评审。</p>');
|
|
202
|
+
await client.doc.updateShare(doc.docCode!, 1, 0);
|
|
203
|
+
await client.doc.publish(doc.docCode!);
|
|
204
|
+
|
|
205
|
+
// push 表格
|
|
206
|
+
const sheet = await client.excel.create('销售日报');
|
|
207
|
+
await client.excel.writeCells(sheet.docCode!, 'A1', [
|
|
208
|
+
['日期', '销售额'],
|
|
209
|
+
['2026-08-13', 12800],
|
|
210
|
+
], 'Sheet1');
|
|
211
|
+
await client.excel.publish(sheet.docCode!);
|
|
185
212
|
```
|
|
186
213
|
|
|
187
214
|
### 图片服务
|
package/dist/index.cjs
CHANGED
|
@@ -75,6 +75,27 @@ var WebhookTypeDescription = {
|
|
|
75
75
|
[11 /* WX_PUSHER */]: "WxPusher",
|
|
76
76
|
[12 /* CUSTOM */]: "\u81EA\u5B9A\u4E49"
|
|
77
77
|
};
|
|
78
|
+
var FormStatus = /* @__PURE__ */ ((FormStatus2) => {
|
|
79
|
+
FormStatus2[FormStatus2["DRAFT"] = 0] = "DRAFT";
|
|
80
|
+
FormStatus2[FormStatus2["COLLECTING"] = 1] = "COLLECTING";
|
|
81
|
+
FormStatus2[FormStatus2["STOPPED"] = 2] = "STOPPED";
|
|
82
|
+
return FormStatus2;
|
|
83
|
+
})(FormStatus || {});
|
|
84
|
+
var FormStatusDescription = {
|
|
85
|
+
[0 /* DRAFT */]: "\u8349\u7A3F",
|
|
86
|
+
[1 /* COLLECTING */]: "\u6536\u96C6\u4E2D",
|
|
87
|
+
[2 /* STOPPED */]: "\u5DF2\u505C\u6B62"
|
|
88
|
+
};
|
|
89
|
+
var SharePerm = /* @__PURE__ */ ((SharePerm2) => {
|
|
90
|
+
SharePerm2[SharePerm2["CLOSED"] = 0] = "CLOSED";
|
|
91
|
+
SharePerm2[SharePerm2["VIEW"] = 1] = "VIEW";
|
|
92
|
+
return SharePerm2;
|
|
93
|
+
})(SharePerm || {});
|
|
94
|
+
var ShareLogin = /* @__PURE__ */ ((ShareLogin2) => {
|
|
95
|
+
ShareLogin2[ShareLogin2["ANONYMOUS"] = 0] = "ANONYMOUS";
|
|
96
|
+
ShareLogin2[ShareLogin2["REQUIRED"] = 1] = "REQUIRED";
|
|
97
|
+
return ShareLogin2;
|
|
98
|
+
})(ShareLogin || {});
|
|
78
99
|
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
79
100
|
ErrorCode3[ErrorCode3["OK"] = 200] = "OK";
|
|
80
101
|
ErrorCode3[ErrorCode3["NOT_LOGIN"] = 302] = "NOT_LOGIN";
|
|
@@ -546,6 +567,218 @@ var ClawBotApi = class extends OpenAbstractApi {
|
|
|
546
567
|
}
|
|
547
568
|
};
|
|
548
569
|
|
|
570
|
+
// src/api/doc-api.ts
|
|
571
|
+
var DocApi = class extends OpenAbstractApi {
|
|
572
|
+
constructor(config, http, mgr) {
|
|
573
|
+
super(config, http, mgr);
|
|
574
|
+
}
|
|
575
|
+
/** 我的文档分页。 */
|
|
576
|
+
list(query) {
|
|
577
|
+
return this.executeOpen(
|
|
578
|
+
"POST",
|
|
579
|
+
"/push/api/open/doc/list",
|
|
580
|
+
query != null ? query : {}
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
/** 创建空白文档。 */
|
|
584
|
+
create(title) {
|
|
585
|
+
return this.executeOpen("POST", "/push/api/open/doc/create", { title });
|
|
586
|
+
}
|
|
587
|
+
/** 获取文档元信息与 HTML 草稿正文。 */
|
|
588
|
+
content(docCode) {
|
|
589
|
+
return this.executeOpen(
|
|
590
|
+
"GET",
|
|
591
|
+
this.appendQuery("/push/api/open/doc/content", { docCode })
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
/** 保存 HTML 草稿(不影响分享页,需再 publish)。 */
|
|
595
|
+
saveContent(docCode, content) {
|
|
596
|
+
return this.executeOpen("POST", "/push/api/open/doc/saveContent", { docCode, content });
|
|
597
|
+
}
|
|
598
|
+
/** 将草稿同步为分享页快照。 */
|
|
599
|
+
publish(docCode) {
|
|
600
|
+
return this.executeOpen(
|
|
601
|
+
"POST",
|
|
602
|
+
this.appendQuery("/push/api/open/doc/publish", { docCode })
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
/** 重命名。 */
|
|
606
|
+
async rename(docCode, title) {
|
|
607
|
+
await this.executeOpen("POST", "/push/api/open/doc/rename", { docCode, title });
|
|
608
|
+
}
|
|
609
|
+
/** 删除文档。 */
|
|
610
|
+
async delete(docCode) {
|
|
611
|
+
await this.executeOpen(
|
|
612
|
+
"POST",
|
|
613
|
+
this.appendQuery("/push/api/open/doc/delete", { docCode })
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* 更新分享设置。
|
|
618
|
+
*
|
|
619
|
+
* @param sharePerm 0 关闭 / 1 开启(仅可查看)
|
|
620
|
+
* @param shareLogin 0 免登录 / 1 需登录;不传则沿用原值
|
|
621
|
+
*/
|
|
622
|
+
updateShare(docCode, sharePerm, shareLogin) {
|
|
623
|
+
const body = { docCode, sharePerm };
|
|
624
|
+
if (shareLogin != null) body.shareLogin = shareLogin;
|
|
625
|
+
return this.executeOpen("POST", "/push/api/open/doc/updateShare", body);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/api/excel-api.ts
|
|
630
|
+
var ExcelApi = class extends OpenAbstractApi {
|
|
631
|
+
constructor(config, http, mgr) {
|
|
632
|
+
super(config, http, mgr);
|
|
633
|
+
}
|
|
634
|
+
/** 我的表格分页。 */
|
|
635
|
+
list(query) {
|
|
636
|
+
return this.executeOpen(
|
|
637
|
+
"POST",
|
|
638
|
+
"/push/api/open/excel/list",
|
|
639
|
+
query != null ? query : {}
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
/** 创建空白表格。 */
|
|
643
|
+
create(title) {
|
|
644
|
+
return this.executeOpen("POST", "/push/api/open/excel/create", { title });
|
|
645
|
+
}
|
|
646
|
+
/** 获取表格元信息与整表 JSON 草稿。 */
|
|
647
|
+
content(docCode) {
|
|
648
|
+
return this.executeOpen(
|
|
649
|
+
"GET",
|
|
650
|
+
this.appendQuery("/push/api/open/excel/content", { docCode })
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* 整表覆盖保存草稿。
|
|
655
|
+
*
|
|
656
|
+
* `content` 可为 JSON 字符串,或工作簿对象(SDK 会序列化)。
|
|
657
|
+
*/
|
|
658
|
+
saveContent(docCode, content) {
|
|
659
|
+
return this.executeOpen("POST", "/push/api/open/excel/saveContent", {
|
|
660
|
+
docCode,
|
|
661
|
+
content: stringifyJsonContent(content)
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* 从指定起始单元格起,按二维数组向右向下写入(草稿)。
|
|
666
|
+
*
|
|
667
|
+
* @param range 起始单元格,如 A1
|
|
668
|
+
* @param values 外层为行、内层为列
|
|
669
|
+
* @param sheetName 工作表名称;不传则写入活动表 / 第一张表
|
|
670
|
+
*/
|
|
671
|
+
writeCells(docCode, range, values, sheetName) {
|
|
672
|
+
const body = { docCode, range, values };
|
|
673
|
+
if (sheetName != null) body.sheetName = sheetName;
|
|
674
|
+
return this.executeOpen("POST", "/push/api/open/excel/writeCells", body);
|
|
675
|
+
}
|
|
676
|
+
/** 将草稿同步为分享页快照。 */
|
|
677
|
+
publish(docCode) {
|
|
678
|
+
return this.executeOpen(
|
|
679
|
+
"POST",
|
|
680
|
+
this.appendQuery("/push/api/open/excel/publish", { docCode })
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
/** 重命名。 */
|
|
684
|
+
async rename(docCode, title) {
|
|
685
|
+
await this.executeOpen("POST", "/push/api/open/excel/rename", { docCode, title });
|
|
686
|
+
}
|
|
687
|
+
/** 删除表格。 */
|
|
688
|
+
async delete(docCode) {
|
|
689
|
+
await this.executeOpen(
|
|
690
|
+
"POST",
|
|
691
|
+
this.appendQuery("/push/api/open/excel/delete", { docCode })
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* 更新分享设置。
|
|
696
|
+
*
|
|
697
|
+
* @param sharePerm 0 关闭 / 1 开启(仅可查看)
|
|
698
|
+
* @param shareLogin 0 免登录 / 1 需登录;不传则沿用原值
|
|
699
|
+
*/
|
|
700
|
+
updateShare(docCode, sharePerm, shareLogin) {
|
|
701
|
+
const body = { docCode, sharePerm };
|
|
702
|
+
if (shareLogin != null) body.shareLogin = shareLogin;
|
|
703
|
+
return this.executeOpen("POST", "/push/api/open/excel/updateShare", body);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
function stringifyJsonContent(content) {
|
|
707
|
+
if (typeof content === "string") {
|
|
708
|
+
return content;
|
|
709
|
+
}
|
|
710
|
+
try {
|
|
711
|
+
return JSON.stringify(content);
|
|
712
|
+
} catch (e) {
|
|
713
|
+
throw new PushPlusError(`\u5E8F\u5217\u5316\u8868\u683C\u5185\u5BB9\u5931\u8D25: ${e.message}`, -1, { cause: e });
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// src/api/form-api.ts
|
|
718
|
+
var FormApi = class extends OpenAbstractApi {
|
|
719
|
+
constructor(config, http, mgr) {
|
|
720
|
+
super(config, http, mgr);
|
|
721
|
+
}
|
|
722
|
+
/** 我的表单分页。 */
|
|
723
|
+
list(query) {
|
|
724
|
+
return this.executeOpen(
|
|
725
|
+
"POST",
|
|
726
|
+
"/push/api/open/form/list",
|
|
727
|
+
query != null ? query : {}
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
/** 创建空白表单(草稿)。 */
|
|
731
|
+
create(title) {
|
|
732
|
+
return this.executeOpen("POST", "/push/api/open/form/create", { title });
|
|
733
|
+
}
|
|
734
|
+
/** 基于已有表单复制一份新草稿。 */
|
|
735
|
+
copy(id) {
|
|
736
|
+
return this.executeOpen(
|
|
737
|
+
"POST",
|
|
738
|
+
this.appendQuery("/push/api/open/form/copy", { id })
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
/** 保存表单设计(仅更新草稿;已发布需再调用 publish)。 */
|
|
742
|
+
async save(req) {
|
|
743
|
+
await this.executeOpen("POST", "/push/api/open/form/save", req);
|
|
744
|
+
}
|
|
745
|
+
/** 表单详情(含草稿题目、主题、设置)。 */
|
|
746
|
+
detail(id) {
|
|
747
|
+
return this.executeOpen(
|
|
748
|
+
"GET",
|
|
749
|
+
this.appendQuery("/push/api/open/form/detail", { id })
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
/** 草稿与发布快照的题目差异。 */
|
|
753
|
+
publishDiff(id) {
|
|
754
|
+
return this.executeOpen(
|
|
755
|
+
"GET",
|
|
756
|
+
this.appendQuery("/push/api/open/form/publishDiff", { id })
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
/** 发布表单,开始收集。 */
|
|
760
|
+
publish(id) {
|
|
761
|
+
return this.executeOpen(
|
|
762
|
+
"POST",
|
|
763
|
+
this.appendQuery("/push/api/open/form/publish", { id })
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
/** 停止收集。 */
|
|
767
|
+
async stop(id) {
|
|
768
|
+
await this.executeOpen(
|
|
769
|
+
"POST",
|
|
770
|
+
this.appendQuery("/push/api/open/form/stop", { id })
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
/** 删除表单(不可恢复)。 */
|
|
774
|
+
async delete(id) {
|
|
775
|
+
await this.executeOpen(
|
|
776
|
+
"POST",
|
|
777
|
+
this.appendQuery("/push/api/open/form/delete", { id })
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
|
|
549
782
|
// src/api/friend-api.ts
|
|
550
783
|
var FriendApi = class extends OpenAbstractApi {
|
|
551
784
|
constructor(config, http, mgr) {
|
|
@@ -1138,7 +1371,7 @@ function resolveConfig(input) {
|
|
|
1138
1371
|
logRequest: (_g = cfg.logRequest) != null ? _g : false,
|
|
1139
1372
|
rateLimitGuardEnabled: (_h = cfg.rateLimitGuardEnabled) != null ? _h : true,
|
|
1140
1373
|
rateLimitCooldownMs: (_i = cfg.rateLimitCooldownMs) != null ? _i : 0,
|
|
1141
|
-
userAgent: (_j = cfg.userAgent) != null ? _j : `@perk-net/perk-pushplus-sdk/1.
|
|
1374
|
+
userAgent: (_j = cfg.userAgent) != null ? _j : `@perk-net/perk-pushplus-sdk/1.2.0`
|
|
1142
1375
|
};
|
|
1143
1376
|
}
|
|
1144
1377
|
|
|
@@ -1233,6 +1466,9 @@ var PushPlusClient = class _PushPlusClient {
|
|
|
1233
1466
|
this.setting = new SettingApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1234
1467
|
this.pre = new PreApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1235
1468
|
this.image = new ImageApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1469
|
+
this.form = new FormApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1470
|
+
this.doc = new DocApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1471
|
+
this.excel = new ExcelApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1236
1472
|
}
|
|
1237
1473
|
/** 与 Java SDK 风格一致的 Builder 入口。 */
|
|
1238
1474
|
static builder() {
|
|
@@ -1476,8 +1712,13 @@ exports.Channel = Channel;
|
|
|
1476
1712
|
exports.ChannelApi = ChannelApi;
|
|
1477
1713
|
exports.ClawBotApi = ClawBotApi;
|
|
1478
1714
|
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
1715
|
+
exports.DocApi = DocApi;
|
|
1479
1716
|
exports.ErrorCode = ErrorCode;
|
|
1717
|
+
exports.ExcelApi = ExcelApi;
|
|
1480
1718
|
exports.FetchHttpRequester = FetchHttpRequester;
|
|
1719
|
+
exports.FormApi = FormApi;
|
|
1720
|
+
exports.FormStatus = FormStatus;
|
|
1721
|
+
exports.FormStatusDescription = FormStatusDescription;
|
|
1481
1722
|
exports.FriendApi = FriendApi;
|
|
1482
1723
|
exports.ImageApi = ImageApi;
|
|
1483
1724
|
exports.MessageApi = MessageApi;
|
|
@@ -1494,6 +1735,8 @@ exports.SendRequestBuilder = SendRequestBuilder;
|
|
|
1494
1735
|
exports.SendStatus = SendStatus;
|
|
1495
1736
|
exports.SendStatusDescription = SendStatusDescription;
|
|
1496
1737
|
exports.SettingApi = SettingApi;
|
|
1738
|
+
exports.ShareLogin = ShareLogin;
|
|
1739
|
+
exports.SharePerm = SharePerm;
|
|
1497
1740
|
exports.Template = Template;
|
|
1498
1741
|
exports.TopicApi = TopicApi;
|
|
1499
1742
|
exports.TopicUserApi = TopicUserApi;
|