@perk-net/perk-pushplus-sdk 1.1.1 → 1.2.1
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 +71 -2
- package/dist/index.cjs +454 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +406 -1
- package/dist/index.d.ts +406 -1
- package/dist/index.global.js +454 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +448 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/base.ts +27 -1
- package/src/api/doc-api.ts +101 -0
- package/src/api/excel-api.ts +143 -0
- package/src/api/form-api.ts +95 -0
- package/src/api/friend-api.ts +38 -1
- package/src/api/open-base.ts +40 -0
- package/src/api/topic-user-api.ts +40 -1
- package/src/client.ts +9 -0
- package/src/config.ts +1 -1
- package/src/enums.ts +37 -0
- package/src/index.ts +27 -0
- package/src/models.ts +215 -0
- package/src/multipart.ts +62 -0
package/src/models.ts
CHANGED
|
@@ -426,6 +426,19 @@ export interface TopicUserListQuery {
|
|
|
426
426
|
params?: Record<string, unknown>;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
+
/** 群组订阅人黑名单列表项。 */
|
|
430
|
+
export interface TopicUserBlacklistItem {
|
|
431
|
+
/** 黑名单记录 ID;解除黑名单时使用。 */
|
|
432
|
+
id?: number;
|
|
433
|
+
/** 被拉黑用户 ID。 */
|
|
434
|
+
userId?: number;
|
|
435
|
+
nickName?: string;
|
|
436
|
+
openId?: string;
|
|
437
|
+
headImgUrl?: string;
|
|
438
|
+
/** 拉黑时间。 */
|
|
439
|
+
createTime?: string;
|
|
440
|
+
}
|
|
441
|
+
|
|
429
442
|
/* ============================== 开放接口 - webhook ============================== */
|
|
430
443
|
|
|
431
444
|
export interface WebhookItem {
|
|
@@ -474,6 +487,18 @@ export interface FriendQrCode {
|
|
|
474
487
|
qrCodeImgUrl?: string;
|
|
475
488
|
}
|
|
476
489
|
|
|
490
|
+
/** 好友黑名单列表项。 */
|
|
491
|
+
export interface FriendBlacklistItem {
|
|
492
|
+
/** 黑名单记录 ID;解除黑名单时使用。 */
|
|
493
|
+
id?: number;
|
|
494
|
+
/** 被拉黑好友 ID。 */
|
|
495
|
+
friendId?: number;
|
|
496
|
+
nickName?: string;
|
|
497
|
+
headImgUrl?: string;
|
|
498
|
+
/** 拉黑时间。 */
|
|
499
|
+
createTime?: string;
|
|
500
|
+
}
|
|
501
|
+
|
|
477
502
|
/* ============================== 开放接口 - clawbot ============================== */
|
|
478
503
|
|
|
479
504
|
export interface ClawBotInfo {
|
|
@@ -658,3 +683,193 @@ export interface ImageItem {
|
|
|
658
683
|
/** 创建时间。 */
|
|
659
684
|
createTime?: string;
|
|
660
685
|
}
|
|
686
|
+
|
|
687
|
+
/* ============================== 开放接口 - form(push 表单) ============================== */
|
|
688
|
+
|
|
689
|
+
/** 我的表单分页查询。官方结构为 `{current, pageSize, params:{keyword, status}}`。 */
|
|
690
|
+
export interface FormListQuery {
|
|
691
|
+
/** 当前所在分页数,默认 1。 */
|
|
692
|
+
current?: number;
|
|
693
|
+
/** 每页大小,默认 20,最大 50。 */
|
|
694
|
+
pageSize?: number;
|
|
695
|
+
params?: {
|
|
696
|
+
/** 按标题关键词搜索。 */
|
|
697
|
+
keyword?: string;
|
|
698
|
+
/** 表单状态:0草稿 / 1收集中 / 2已停止。 */
|
|
699
|
+
status?: number;
|
|
700
|
+
[key: string]: unknown;
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/** 表单封面页配置。 */
|
|
705
|
+
export interface FormCover {
|
|
706
|
+
enabled?: boolean;
|
|
707
|
+
image?: string;
|
|
708
|
+
buttonText?: string;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** 表单主题外观。 */
|
|
712
|
+
export interface FormTheme {
|
|
713
|
+
primaryColor?: string;
|
|
714
|
+
backgroundColor?: string;
|
|
715
|
+
headerImage?: string;
|
|
716
|
+
backgroundImage?: string;
|
|
717
|
+
cover?: FormCover;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/** 表单收集 / 展示设置。 */
|
|
721
|
+
export interface FormSettings {
|
|
722
|
+
endTime?: string | null;
|
|
723
|
+
maxResponses?: number | null;
|
|
724
|
+
oncePerUser?: boolean;
|
|
725
|
+
allowAnonymous?: boolean;
|
|
726
|
+
password?: string;
|
|
727
|
+
showQuestionNumber?: boolean;
|
|
728
|
+
onePerPage?: boolean;
|
|
729
|
+
showPrevButton?: boolean;
|
|
730
|
+
hideTitle?: boolean;
|
|
731
|
+
hideCopyright?: boolean;
|
|
732
|
+
hideAd?: boolean;
|
|
733
|
+
showOutline?: boolean;
|
|
734
|
+
thankText?: string;
|
|
735
|
+
redirectEnabled?: boolean;
|
|
736
|
+
redirectUrl?: string;
|
|
737
|
+
allowEdit?: boolean;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* 表单题目。不同题型字段不同,除常用字段外可携带任意扩展属性。
|
|
742
|
+
*
|
|
743
|
+
* type 常用取值:input / textarea / radio / checkbox / select / number / date / rate 等。
|
|
744
|
+
*/
|
|
745
|
+
export interface FormItem {
|
|
746
|
+
id?: string;
|
|
747
|
+
type?: string;
|
|
748
|
+
alias?: string;
|
|
749
|
+
label?: string;
|
|
750
|
+
description?: string;
|
|
751
|
+
required?: boolean;
|
|
752
|
+
placeholder?: string;
|
|
753
|
+
options?: unknown[];
|
|
754
|
+
rows?: unknown[];
|
|
755
|
+
columns?: unknown[];
|
|
756
|
+
allowOther?: boolean;
|
|
757
|
+
[key: string]: unknown;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/** 表单列表项 / 创建、复制结果(不含题目明细)。 */
|
|
761
|
+
export interface FormListItem {
|
|
762
|
+
id?: number;
|
|
763
|
+
formCode?: string;
|
|
764
|
+
fillUrl?: string;
|
|
765
|
+
title?: string;
|
|
766
|
+
description?: string;
|
|
767
|
+
status?: number;
|
|
768
|
+
responseCount?: number;
|
|
769
|
+
publishTime?: string;
|
|
770
|
+
createTime?: string;
|
|
771
|
+
updateTime?: string;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/** 保存表单设计请求。 */
|
|
775
|
+
export interface FormSaveRequest {
|
|
776
|
+
id: number;
|
|
777
|
+
title: string;
|
|
778
|
+
description?: string;
|
|
779
|
+
items?: FormItem[];
|
|
780
|
+
theme?: FormTheme;
|
|
781
|
+
settings?: FormSettings;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/** 表单详情(含草稿题目、主题、设置)。 */
|
|
785
|
+
export interface FormDetail extends FormListItem {
|
|
786
|
+
items?: FormItem[];
|
|
787
|
+
theme?: FormTheme;
|
|
788
|
+
settings?: FormSettings;
|
|
789
|
+
publishDirty?: boolean;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/** 草稿题目与发布快照差异。 */
|
|
793
|
+
export interface FormPublishDiff {
|
|
794
|
+
dirty?: boolean;
|
|
795
|
+
breaking?: boolean;
|
|
796
|
+
responseCount?: number;
|
|
797
|
+
added?: string[];
|
|
798
|
+
removed?: string[];
|
|
799
|
+
typeChanged?: string[];
|
|
800
|
+
optionChanged?: string[];
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** 发布表单结果。 */
|
|
804
|
+
export interface FormPublishResult {
|
|
805
|
+
id?: number;
|
|
806
|
+
formCode?: string;
|
|
807
|
+
fillUrl?: string;
|
|
808
|
+
title?: string;
|
|
809
|
+
status?: number;
|
|
810
|
+
previousStatus?: number;
|
|
811
|
+
publishDirty?: boolean;
|
|
812
|
+
publishTime?: string;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/* ============================== 开放接口 - doc / excel 共用查询 ============================== */
|
|
816
|
+
|
|
817
|
+
/** 文档 / 表格分页查询。官方结构为 `{current, pageSize, params:{keyword, shareEnabled}}`。 */
|
|
818
|
+
export interface DocListQuery {
|
|
819
|
+
/** 当前所在分页数,默认 1。 */
|
|
820
|
+
current?: number;
|
|
821
|
+
/** 每页大小,默认 20,最大 50。 */
|
|
822
|
+
pageSize?: number;
|
|
823
|
+
params?: {
|
|
824
|
+
keyword?: string;
|
|
825
|
+
/** true 时仅返回已开启分享的记录。 */
|
|
826
|
+
shareEnabled?: boolean;
|
|
827
|
+
[key: string]: unknown;
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/** 文档 / 表格列表项。 */
|
|
832
|
+
export interface DocListItem {
|
|
833
|
+
docCode?: string;
|
|
834
|
+
shareUrl?: string;
|
|
835
|
+
title?: string;
|
|
836
|
+
sharePerm?: number;
|
|
837
|
+
shareLogin?: number;
|
|
838
|
+
perm?: number;
|
|
839
|
+
published?: boolean;
|
|
840
|
+
publishTime?: string;
|
|
841
|
+
createTime?: string;
|
|
842
|
+
updateTime?: string;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** 文档信息(不含正文)。 */
|
|
846
|
+
export interface DocVo extends DocListItem {
|
|
847
|
+
publishDirty?: boolean;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** 文档内容(HTML 草稿)。 */
|
|
851
|
+
export interface DocContent extends DocVo {
|
|
852
|
+
content?: string;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** 表格信息(不含正文)。与文档结构相同,独立类型便于区分。 */
|
|
856
|
+
export interface ExcelVo extends DocListItem {
|
|
857
|
+
publishDirty?: boolean;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/** 表格内容(整表 JSON 字符串草稿)。 */
|
|
861
|
+
export interface ExcelContent extends ExcelVo {
|
|
862
|
+
/** 整表草稿 JSON 字符串。 */
|
|
863
|
+
content?: string;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** 按区域写入单元格请求。 */
|
|
867
|
+
export interface ExcelWriteCellsRequest {
|
|
868
|
+
docCode: string;
|
|
869
|
+
/** 工作表名称;不传则写入活动表 / 第一张表。 */
|
|
870
|
+
sheetName?: string;
|
|
871
|
+
/** 起始单元格,如 A1。 */
|
|
872
|
+
range: string;
|
|
873
|
+
/** 二维数组,外层为行、内层为列。 */
|
|
874
|
+
values: unknown[][];
|
|
875
|
+
}
|
package/src/multipart.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PushPlusError } from './exception';
|
|
2
|
+
|
|
3
|
+
/** 二进制文件输入。 */
|
|
4
|
+
export type FileInput = Uint8Array | ArrayBuffer | Blob;
|
|
5
|
+
|
|
6
|
+
export interface FileMultipart {
|
|
7
|
+
contentType: string;
|
|
8
|
+
body: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 构造仅含一个 file 字段的 multipart/form-data 请求体。 */
|
|
12
|
+
export function buildFileMultipart(
|
|
13
|
+
fileName: string,
|
|
14
|
+
contentType: string | undefined,
|
|
15
|
+
fileBytes: Uint8Array,
|
|
16
|
+
): FileMultipart {
|
|
17
|
+
if (fileBytes == null || fileBytes.byteLength === 0) {
|
|
18
|
+
throw new PushPlusError('上传文件内容不能为空');
|
|
19
|
+
}
|
|
20
|
+
const safeName = fileName && fileName.trim() ? fileName : 'file';
|
|
21
|
+
const mime = contentType && contentType.trim() ? contentType : 'application/octet-stream';
|
|
22
|
+
const boundary = '----PushPlusBoundary' + randomBoundarySuffix();
|
|
23
|
+
const crlf = '\r\n';
|
|
24
|
+
const enc = new TextEncoder();
|
|
25
|
+
const head = enc.encode(
|
|
26
|
+
`--${boundary}${crlf}` +
|
|
27
|
+
`Content-Disposition: form-data; name="file"; filename="${escapeFileName(safeName)}"${crlf}` +
|
|
28
|
+
`Content-Type: ${mime}${crlf}${crlf}`,
|
|
29
|
+
);
|
|
30
|
+
const tail = enc.encode(`${crlf}--${boundary}--${crlf}`);
|
|
31
|
+
const body = new Uint8Array(head.byteLength + fileBytes.byteLength + tail.byteLength);
|
|
32
|
+
body.set(head, 0);
|
|
33
|
+
body.set(fileBytes, head.byteLength);
|
|
34
|
+
body.set(tail, head.byteLength + fileBytes.byteLength);
|
|
35
|
+
return { contentType: `multipart/form-data; boundary=${boundary}`, body };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function toFileBytes(file: FileInput): Promise<Uint8Array> {
|
|
39
|
+
if (file instanceof Uint8Array) {
|
|
40
|
+
return file;
|
|
41
|
+
}
|
|
42
|
+
if (file instanceof ArrayBuffer) {
|
|
43
|
+
return new Uint8Array(file);
|
|
44
|
+
}
|
|
45
|
+
if (typeof Blob !== 'undefined' && file instanceof Blob) {
|
|
46
|
+
const ab = await file.arrayBuffer();
|
|
47
|
+
return new Uint8Array(ab);
|
|
48
|
+
}
|
|
49
|
+
throw new PushPlusError(`不支持的上传文件类型: ${Object.prototype.toString.call(file)}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function escapeFileName(name: string): string {
|
|
53
|
+
return name.replace(/"/g, '_').replace(/\r/g, ' ').replace(/\n/g, ' ');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function randomBoundarySuffix(): string {
|
|
57
|
+
let s = '';
|
|
58
|
+
for (let i = 0; i < 32; i++) {
|
|
59
|
+
s += Math.floor(Math.random() * 16).toString(16);
|
|
60
|
+
}
|
|
61
|
+
return s;
|
|
62
|
+
}
|