@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/dist/index.js
CHANGED
|
@@ -73,6 +73,27 @@ var WebhookTypeDescription = {
|
|
|
73
73
|
[11 /* WX_PUSHER */]: "WxPusher",
|
|
74
74
|
[12 /* CUSTOM */]: "\u81EA\u5B9A\u4E49"
|
|
75
75
|
};
|
|
76
|
+
var FormStatus = /* @__PURE__ */ ((FormStatus2) => {
|
|
77
|
+
FormStatus2[FormStatus2["DRAFT"] = 0] = "DRAFT";
|
|
78
|
+
FormStatus2[FormStatus2["COLLECTING"] = 1] = "COLLECTING";
|
|
79
|
+
FormStatus2[FormStatus2["STOPPED"] = 2] = "STOPPED";
|
|
80
|
+
return FormStatus2;
|
|
81
|
+
})(FormStatus || {});
|
|
82
|
+
var FormStatusDescription = {
|
|
83
|
+
[0 /* DRAFT */]: "\u8349\u7A3F",
|
|
84
|
+
[1 /* COLLECTING */]: "\u6536\u96C6\u4E2D",
|
|
85
|
+
[2 /* STOPPED */]: "\u5DF2\u505C\u6B62"
|
|
86
|
+
};
|
|
87
|
+
var SharePerm = /* @__PURE__ */ ((SharePerm2) => {
|
|
88
|
+
SharePerm2[SharePerm2["CLOSED"] = 0] = "CLOSED";
|
|
89
|
+
SharePerm2[SharePerm2["VIEW"] = 1] = "VIEW";
|
|
90
|
+
return SharePerm2;
|
|
91
|
+
})(SharePerm || {});
|
|
92
|
+
var ShareLogin = /* @__PURE__ */ ((ShareLogin2) => {
|
|
93
|
+
ShareLogin2[ShareLogin2["ANONYMOUS"] = 0] = "ANONYMOUS";
|
|
94
|
+
ShareLogin2[ShareLogin2["REQUIRED"] = 1] = "REQUIRED";
|
|
95
|
+
return ShareLogin2;
|
|
96
|
+
})(ShareLogin || {});
|
|
76
97
|
var ErrorCode = /* @__PURE__ */ ((ErrorCode3) => {
|
|
77
98
|
ErrorCode3[ErrorCode3["OK"] = 200] = "OK";
|
|
78
99
|
ErrorCode3[ErrorCode3["NOT_LOGIN"] = 302] = "NOT_LOGIN";
|
|
@@ -352,6 +373,26 @@ var AbstractApi = class {
|
|
|
352
373
|
}
|
|
353
374
|
return parseApiResponse(resp);
|
|
354
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* 执行带二进制请求体的请求并返回原始 ApiResponse(不进行 code 校验)。
|
|
378
|
+
* 用于 multipart 上传等场景。
|
|
379
|
+
*/
|
|
380
|
+
async executeRaw(method, path, headers, body) {
|
|
381
|
+
const url = this.resolveUrl(path);
|
|
382
|
+
const resp = await callExecuteRaw(this.http, {
|
|
383
|
+
method,
|
|
384
|
+
url,
|
|
385
|
+
headers: headers != null ? headers : void 0,
|
|
386
|
+
body
|
|
387
|
+
});
|
|
388
|
+
if (!isSuccessfulHttpStatus(resp.statusCode)) {
|
|
389
|
+
throw new PushPlusError(
|
|
390
|
+
`PushPlus \u63A5\u53E3 HTTP \u8C03\u7528\u5931\u8D25: status=${resp.statusCode}, body=${resp.body}`,
|
|
391
|
+
resp.statusCode
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
return parseApiResponse(resp);
|
|
395
|
+
}
|
|
355
396
|
/** 执行请求并直接返回 data;非 200 抛出异常。 */
|
|
356
397
|
async executeForData(method, path, headers, body) {
|
|
357
398
|
var _a;
|
|
@@ -482,6 +523,39 @@ var _OpenAbstractApi = class _OpenAbstractApi extends AbstractApi {
|
|
|
482
523
|
(_b = resp.code) != null ? _b : -1
|
|
483
524
|
);
|
|
484
525
|
}
|
|
526
|
+
/** 以 multipart 上传文件(自动携带 access-key;code=401 时刷新后重试一次)。 */
|
|
527
|
+
executeOpenMultipart(path, multipart) {
|
|
528
|
+
return this.executeOpenRaw("POST", path, multipart.body, {
|
|
529
|
+
"Content-Type": multipart.contentType
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* 执行带二进制 body 的开放接口请求;当返回 code=401 时自动刷新 key 并重试一次。
|
|
534
|
+
*/
|
|
535
|
+
async executeOpenRaw(method, path, body, extraHeaders) {
|
|
536
|
+
var _a, _b;
|
|
537
|
+
const headers = { ...await this.headersWithAccessKey(), ...extraHeaders != null ? extraHeaders : {} };
|
|
538
|
+
const resp = await this.executeRaw(method, path, headers, body);
|
|
539
|
+
if (isApiSuccess(resp)) {
|
|
540
|
+
return resp.data;
|
|
541
|
+
}
|
|
542
|
+
if (resp.code === _OpenAbstractApi.CODE_ACCESS_KEY_INVALID) {
|
|
543
|
+
this.accessKeyManager.invalidate();
|
|
544
|
+
const retryHeaders = { ...await this.headersWithAccessKey(), ...extraHeaders != null ? extraHeaders : {} };
|
|
545
|
+
const retry = await this.executeRaw(method, path, retryHeaders, body);
|
|
546
|
+
if (isApiSuccess(retry)) {
|
|
547
|
+
return retry.data;
|
|
548
|
+
}
|
|
549
|
+
throw new PushPlusError(
|
|
550
|
+
`PushPlus \u5F00\u653E\u63A5\u53E3\u4E1A\u52A1\u5931\u8D25(\u91CD\u8BD5\u540E): code=${retry.code}, msg=${retry.msg}`,
|
|
551
|
+
(_a = retry.code) != null ? _a : -1
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
throw new PushPlusError(
|
|
555
|
+
`PushPlus \u5F00\u653E\u63A5\u53E3\u4E1A\u52A1\u5931\u8D25: code=${resp.code}, msg=${resp.msg}`,
|
|
556
|
+
(_b = resp.code) != null ? _b : -1
|
|
557
|
+
);
|
|
558
|
+
}
|
|
485
559
|
};
|
|
486
560
|
_OpenAbstractApi.HEADER_ACCESS_KEY = "access-key";
|
|
487
561
|
/** PushPlus AccessKey 失效相关的业务码(用于触发自动重试)。 */
|
|
@@ -544,6 +618,301 @@ var ClawBotApi = class extends OpenAbstractApi {
|
|
|
544
618
|
}
|
|
545
619
|
};
|
|
546
620
|
|
|
621
|
+
// src/multipart.ts
|
|
622
|
+
function buildFileMultipart(fileName, contentType, fileBytes) {
|
|
623
|
+
if (fileBytes == null || fileBytes.byteLength === 0) {
|
|
624
|
+
throw new PushPlusError("\u4E0A\u4F20\u6587\u4EF6\u5185\u5BB9\u4E0D\u80FD\u4E3A\u7A7A");
|
|
625
|
+
}
|
|
626
|
+
const safeName = fileName && fileName.trim() ? fileName : "file";
|
|
627
|
+
const mime = contentType && contentType.trim() ? contentType : "application/octet-stream";
|
|
628
|
+
const boundary = "----PushPlusBoundary" + randomBoundarySuffix();
|
|
629
|
+
const crlf = "\r\n";
|
|
630
|
+
const enc = new TextEncoder();
|
|
631
|
+
const head = enc.encode(
|
|
632
|
+
`--${boundary}${crlf}Content-Disposition: form-data; name="file"; filename="${escapeFileName(safeName)}"${crlf}Content-Type: ${mime}${crlf}${crlf}`
|
|
633
|
+
);
|
|
634
|
+
const tail = enc.encode(`${crlf}--${boundary}--${crlf}`);
|
|
635
|
+
const body = new Uint8Array(head.byteLength + fileBytes.byteLength + tail.byteLength);
|
|
636
|
+
body.set(head, 0);
|
|
637
|
+
body.set(fileBytes, head.byteLength);
|
|
638
|
+
body.set(tail, head.byteLength + fileBytes.byteLength);
|
|
639
|
+
return { contentType: `multipart/form-data; boundary=${boundary}`, body };
|
|
640
|
+
}
|
|
641
|
+
async function toFileBytes(file) {
|
|
642
|
+
if (file instanceof Uint8Array) {
|
|
643
|
+
return file;
|
|
644
|
+
}
|
|
645
|
+
if (file instanceof ArrayBuffer) {
|
|
646
|
+
return new Uint8Array(file);
|
|
647
|
+
}
|
|
648
|
+
if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
649
|
+
const ab = await file.arrayBuffer();
|
|
650
|
+
return new Uint8Array(ab);
|
|
651
|
+
}
|
|
652
|
+
throw new PushPlusError(`\u4E0D\u652F\u6301\u7684\u4E0A\u4F20\u6587\u4EF6\u7C7B\u578B: ${Object.prototype.toString.call(file)}`);
|
|
653
|
+
}
|
|
654
|
+
function escapeFileName(name) {
|
|
655
|
+
return name.replace(/"/g, "_").replace(/\r/g, " ").replace(/\n/g, " ");
|
|
656
|
+
}
|
|
657
|
+
function randomBoundarySuffix() {
|
|
658
|
+
let s = "";
|
|
659
|
+
for (let i = 0; i < 32; i++) {
|
|
660
|
+
s += Math.floor(Math.random() * 16).toString(16);
|
|
661
|
+
}
|
|
662
|
+
return s;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// src/api/doc-api.ts
|
|
666
|
+
var DocApi = class extends OpenAbstractApi {
|
|
667
|
+
constructor(config, http, mgr) {
|
|
668
|
+
super(config, http, mgr);
|
|
669
|
+
}
|
|
670
|
+
/** 我的文档分页。 */
|
|
671
|
+
list(query) {
|
|
672
|
+
return this.executeOpen(
|
|
673
|
+
"POST",
|
|
674
|
+
"/push/api/open/doc/list",
|
|
675
|
+
query != null ? query : {}
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
/** 创建空白文档。 */
|
|
679
|
+
create(title) {
|
|
680
|
+
return this.executeOpen("POST", "/push/api/open/doc/create", { title });
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* 导入 Word(.docx)创建文档。
|
|
684
|
+
*
|
|
685
|
+
* 标题默认取文件名;创建后默认关闭分享,需再调用 publish 才会同步到分享页。
|
|
686
|
+
*/
|
|
687
|
+
async importWord(file, fileName = "document.docx") {
|
|
688
|
+
const bytes = await toFileBytes(file);
|
|
689
|
+
const name = fileName && fileName.trim() ? fileName : "document.docx";
|
|
690
|
+
return this.executeOpenMultipart(
|
|
691
|
+
"/push/api/open/doc/import",
|
|
692
|
+
buildFileMultipart(name, guessDocxContentType(name), bytes)
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
/** 获取文档元信息与 HTML 草稿正文。 */
|
|
696
|
+
content(docCode) {
|
|
697
|
+
return this.executeOpen(
|
|
698
|
+
"GET",
|
|
699
|
+
this.appendQuery("/push/api/open/doc/content", { docCode })
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
/** 保存 HTML 草稿(不影响分享页,需再 publish)。 */
|
|
703
|
+
saveContent(docCode, content) {
|
|
704
|
+
return this.executeOpen("POST", "/push/api/open/doc/saveContent", { docCode, content });
|
|
705
|
+
}
|
|
706
|
+
/** 将草稿同步为分享页快照。 */
|
|
707
|
+
publish(docCode) {
|
|
708
|
+
return this.executeOpen(
|
|
709
|
+
"POST",
|
|
710
|
+
this.appendQuery("/push/api/open/doc/publish", { docCode })
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
/** 重命名。 */
|
|
714
|
+
async rename(docCode, title) {
|
|
715
|
+
await this.executeOpen("POST", "/push/api/open/doc/rename", { docCode, title });
|
|
716
|
+
}
|
|
717
|
+
/** 删除文档。 */
|
|
718
|
+
async delete(docCode) {
|
|
719
|
+
await this.executeOpen(
|
|
720
|
+
"POST",
|
|
721
|
+
this.appendQuery("/push/api/open/doc/delete", { docCode })
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* 更新分享设置。
|
|
726
|
+
*
|
|
727
|
+
* @param sharePerm 0 关闭 / 1 开启(仅可查看)
|
|
728
|
+
* @param shareLogin 0 免登录 / 1 需登录;不传则沿用原值
|
|
729
|
+
*/
|
|
730
|
+
updateShare(docCode, sharePerm, shareLogin) {
|
|
731
|
+
const body = { docCode, sharePerm };
|
|
732
|
+
if (shareLogin != null) body.shareLogin = shareLogin;
|
|
733
|
+
return this.executeOpen("POST", "/push/api/open/doc/updateShare", body);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
function guessDocxContentType(name) {
|
|
737
|
+
return name.toLowerCase().endsWith(".docx") ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/octet-stream";
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// src/api/excel-api.ts
|
|
741
|
+
var ExcelApi = class extends OpenAbstractApi {
|
|
742
|
+
constructor(config, http, mgr) {
|
|
743
|
+
super(config, http, mgr);
|
|
744
|
+
}
|
|
745
|
+
/** 我的表格分页。 */
|
|
746
|
+
list(query) {
|
|
747
|
+
return this.executeOpen(
|
|
748
|
+
"POST",
|
|
749
|
+
"/push/api/open/excel/list",
|
|
750
|
+
query != null ? query : {}
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
/** 创建空白表格。 */
|
|
754
|
+
create(title) {
|
|
755
|
+
return this.executeOpen("POST", "/push/api/open/excel/create", { title });
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* 导入 Excel(.xlsx / .xls)创建表格。
|
|
759
|
+
*
|
|
760
|
+
* 标题默认取文件名;创建后默认关闭分享,需再调用 publish 才会同步到分享页。
|
|
761
|
+
*/
|
|
762
|
+
async importExcel(file, fileName = "workbook.xlsx") {
|
|
763
|
+
const bytes = await toFileBytes(file);
|
|
764
|
+
const name = fileName && fileName.trim() ? fileName : "workbook.xlsx";
|
|
765
|
+
return this.executeOpenMultipart(
|
|
766
|
+
"/push/api/open/excel/import",
|
|
767
|
+
buildFileMultipart(name, guessExcelContentType(name), bytes)
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
/** 获取表格元信息与整表 JSON 草稿。 */
|
|
771
|
+
content(docCode) {
|
|
772
|
+
return this.executeOpen(
|
|
773
|
+
"GET",
|
|
774
|
+
this.appendQuery("/push/api/open/excel/content", { docCode })
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* 整表覆盖保存草稿。
|
|
779
|
+
*
|
|
780
|
+
* `content` 可为 JSON 字符串,或工作簿对象(SDK 会序列化)。
|
|
781
|
+
*/
|
|
782
|
+
saveContent(docCode, content) {
|
|
783
|
+
return this.executeOpen("POST", "/push/api/open/excel/saveContent", {
|
|
784
|
+
docCode,
|
|
785
|
+
content: stringifyJsonContent(content)
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* 从指定起始单元格起,按二维数组向右向下写入(草稿)。
|
|
790
|
+
*
|
|
791
|
+
* @param range 起始单元格,如 A1
|
|
792
|
+
* @param values 外层为行、内层为列
|
|
793
|
+
* @param sheetName 工作表名称;不传则写入活动表 / 第一张表
|
|
794
|
+
*/
|
|
795
|
+
writeCells(docCode, range, values, sheetName) {
|
|
796
|
+
const body = { docCode, range, values };
|
|
797
|
+
if (sheetName != null) body.sheetName = sheetName;
|
|
798
|
+
return this.executeOpen("POST", "/push/api/open/excel/writeCells", body);
|
|
799
|
+
}
|
|
800
|
+
/** 将草稿同步为分享页快照。 */
|
|
801
|
+
publish(docCode) {
|
|
802
|
+
return this.executeOpen(
|
|
803
|
+
"POST",
|
|
804
|
+
this.appendQuery("/push/api/open/excel/publish", { docCode })
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
/** 重命名。 */
|
|
808
|
+
async rename(docCode, title) {
|
|
809
|
+
await this.executeOpen("POST", "/push/api/open/excel/rename", { docCode, title });
|
|
810
|
+
}
|
|
811
|
+
/** 删除表格。 */
|
|
812
|
+
async delete(docCode) {
|
|
813
|
+
await this.executeOpen(
|
|
814
|
+
"POST",
|
|
815
|
+
this.appendQuery("/push/api/open/excel/delete", { docCode })
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* 更新分享设置。
|
|
820
|
+
*
|
|
821
|
+
* @param sharePerm 0 关闭 / 1 开启(仅可查看)
|
|
822
|
+
* @param shareLogin 0 免登录 / 1 需登录;不传则沿用原值
|
|
823
|
+
*/
|
|
824
|
+
updateShare(docCode, sharePerm, shareLogin) {
|
|
825
|
+
const body = { docCode, sharePerm };
|
|
826
|
+
if (shareLogin != null) body.shareLogin = shareLogin;
|
|
827
|
+
return this.executeOpen("POST", "/push/api/open/excel/updateShare", body);
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
function stringifyJsonContent(content) {
|
|
831
|
+
if (typeof content === "string") {
|
|
832
|
+
return content;
|
|
833
|
+
}
|
|
834
|
+
try {
|
|
835
|
+
return JSON.stringify(content);
|
|
836
|
+
} catch (e) {
|
|
837
|
+
throw new PushPlusError(`\u5E8F\u5217\u5316\u8868\u683C\u5185\u5BB9\u5931\u8D25: ${e.message}`, -1, { cause: e });
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function guessExcelContentType(name) {
|
|
841
|
+
const lower = name.toLowerCase();
|
|
842
|
+
if (lower.endsWith(".xlsx")) {
|
|
843
|
+
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
844
|
+
}
|
|
845
|
+
if (lower.endsWith(".xls")) {
|
|
846
|
+
return "application/vnd.ms-excel";
|
|
847
|
+
}
|
|
848
|
+
return "application/octet-stream";
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// src/api/form-api.ts
|
|
852
|
+
var FormApi = class extends OpenAbstractApi {
|
|
853
|
+
constructor(config, http, mgr) {
|
|
854
|
+
super(config, http, mgr);
|
|
855
|
+
}
|
|
856
|
+
/** 我的表单分页。 */
|
|
857
|
+
list(query) {
|
|
858
|
+
return this.executeOpen(
|
|
859
|
+
"POST",
|
|
860
|
+
"/push/api/open/form/list",
|
|
861
|
+
query != null ? query : {}
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
/** 创建空白表单(草稿)。 */
|
|
865
|
+
create(title) {
|
|
866
|
+
return this.executeOpen("POST", "/push/api/open/form/create", { title });
|
|
867
|
+
}
|
|
868
|
+
/** 基于已有表单复制一份新草稿。 */
|
|
869
|
+
copy(id) {
|
|
870
|
+
return this.executeOpen(
|
|
871
|
+
"POST",
|
|
872
|
+
this.appendQuery("/push/api/open/form/copy", { id })
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
/** 保存表单设计(仅更新草稿;已发布需再调用 publish)。 */
|
|
876
|
+
async save(req) {
|
|
877
|
+
await this.executeOpen("POST", "/push/api/open/form/save", req);
|
|
878
|
+
}
|
|
879
|
+
/** 表单详情(含草稿题目、主题、设置)。 */
|
|
880
|
+
detail(id) {
|
|
881
|
+
return this.executeOpen(
|
|
882
|
+
"GET",
|
|
883
|
+
this.appendQuery("/push/api/open/form/detail", { id })
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
/** 草稿与发布快照的题目差异。 */
|
|
887
|
+
publishDiff(id) {
|
|
888
|
+
return this.executeOpen(
|
|
889
|
+
"GET",
|
|
890
|
+
this.appendQuery("/push/api/open/form/publishDiff", { id })
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
/** 发布表单,开始收集。 */
|
|
894
|
+
publish(id) {
|
|
895
|
+
return this.executeOpen(
|
|
896
|
+
"POST",
|
|
897
|
+
this.appendQuery("/push/api/open/form/publish", { id })
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
/** 停止收集。 */
|
|
901
|
+
async stop(id) {
|
|
902
|
+
await this.executeOpen(
|
|
903
|
+
"POST",
|
|
904
|
+
this.appendQuery("/push/api/open/form/stop", { id })
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
/** 删除表单(不可恢复)。 */
|
|
908
|
+
async delete(id) {
|
|
909
|
+
await this.executeOpen(
|
|
910
|
+
"POST",
|
|
911
|
+
this.appendQuery("/push/api/open/form/delete", { id })
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
|
|
547
916
|
// src/api/friend-api.ts
|
|
548
917
|
var FriendApi = class extends OpenAbstractApi {
|
|
549
918
|
constructor(config, http, mgr) {
|
|
@@ -573,6 +942,40 @@ var FriendApi = class extends OpenAbstractApi {
|
|
|
573
942
|
async editRemark(id, remark) {
|
|
574
943
|
await this.executeOpen("POST", "/api/open/friend/editRemark", { id, remark });
|
|
575
944
|
}
|
|
945
|
+
/**
|
|
946
|
+
* 5. 将好友加入黑名单。
|
|
947
|
+
*
|
|
948
|
+
* 加入后将解除双方好友关系,对方无法再添加你。不能将自己加入黑名单,仅可将已有好友加入黑名单。
|
|
949
|
+
*
|
|
950
|
+
* @param friendId 好友 id(好友列表中的 friendId 字段)
|
|
951
|
+
*/
|
|
952
|
+
async addBlacklist(friendId) {
|
|
953
|
+
await this.executeOpen(
|
|
954
|
+
"POST",
|
|
955
|
+
this.appendQuery("/api/open/friend/addBlacklist", { friendId })
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
/** 6. 好友黑名单列表。 */
|
|
959
|
+
blacklistList(query) {
|
|
960
|
+
return this.executeOpen(
|
|
961
|
+
"POST",
|
|
962
|
+
"/api/open/friend/blacklistList",
|
|
963
|
+
query != null ? query : {}
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* 7. 解除好友黑名单。
|
|
968
|
+
*
|
|
969
|
+
* 解除后不会自动恢复好友关系,需重新扫码添加。
|
|
970
|
+
*
|
|
971
|
+
* @param id 黑名单记录 ID(黑名单列表中的 id 字段)
|
|
972
|
+
*/
|
|
973
|
+
async removeBlacklist(id) {
|
|
974
|
+
await this.executeOpen(
|
|
975
|
+
"POST",
|
|
976
|
+
this.appendQuery("/api/open/friend/removeBlacklist", { id })
|
|
977
|
+
);
|
|
978
|
+
}
|
|
576
979
|
};
|
|
577
980
|
|
|
578
981
|
// src/api/image-api.ts
|
|
@@ -621,7 +1024,7 @@ var ImageApi = class extends OpenAbstractApi {
|
|
|
621
1024
|
}
|
|
622
1025
|
const fileName = options.fileName || "file";
|
|
623
1026
|
const contentType = options.contentType || guessContentTypeByName(fileName) || "application/octet-stream";
|
|
624
|
-
const boundary = "----PushPlusBoundary" +
|
|
1027
|
+
const boundary = "----PushPlusBoundary" + randomBoundarySuffix2();
|
|
625
1028
|
const body = buildMultipartBody(boundary, uploadToken, fileName, contentType, bytes);
|
|
626
1029
|
const resp = await callExecuteRaw(this.http, {
|
|
627
1030
|
method: "POST",
|
|
@@ -707,7 +1110,7 @@ function buildMultipartBody(boundary, uploadToken, fileName, contentType, fileBy
|
|
|
707
1110
|
const crlf = "\r\n";
|
|
708
1111
|
const enc = new TextEncoder();
|
|
709
1112
|
const head = enc.encode(
|
|
710
|
-
`--${boundary}${crlf}Content-Disposition: form-data; name="token"${crlf}${crlf}${uploadToken}${crlf}--${boundary}${crlf}Content-Disposition: form-data; name="file"; filename="${
|
|
1113
|
+
`--${boundary}${crlf}Content-Disposition: form-data; name="token"${crlf}${crlf}${uploadToken}${crlf}--${boundary}${crlf}Content-Disposition: form-data; name="file"; filename="${escapeFileName2(fileName)}"${crlf}Content-Type: ${contentType}${crlf}${crlf}`
|
|
711
1114
|
);
|
|
712
1115
|
const tail = enc.encode(`${crlf}--${boundary}--${crlf}`);
|
|
713
1116
|
const out = new Uint8Array(head.byteLength + fileBytes.byteLength + tail.byteLength);
|
|
@@ -716,7 +1119,7 @@ function buildMultipartBody(boundary, uploadToken, fileName, contentType, fileBy
|
|
|
716
1119
|
out.set(tail, head.byteLength + fileBytes.byteLength);
|
|
717
1120
|
return out;
|
|
718
1121
|
}
|
|
719
|
-
function
|
|
1122
|
+
function escapeFileName2(name) {
|
|
720
1123
|
return name.replace(/"/g, "_").replace(/\r/g, " ").replace(/\n/g, " ");
|
|
721
1124
|
}
|
|
722
1125
|
function guessContentTypeByName(name) {
|
|
@@ -729,7 +1132,7 @@ function guessContentTypeByName(name) {
|
|
|
729
1132
|
if (lower.endsWith(".svg")) return "image/svg+xml";
|
|
730
1133
|
return null;
|
|
731
1134
|
}
|
|
732
|
-
function
|
|
1135
|
+
function randomBoundarySuffix2() {
|
|
733
1136
|
let s = "";
|
|
734
1137
|
for (let i = 0; i < 32; i++) {
|
|
735
1138
|
s += Math.floor(Math.random() * 16).toString(16);
|
|
@@ -1072,6 +1475,42 @@ var TopicUserApi = class extends OpenAbstractApi {
|
|
|
1072
1475
|
async editRemark(id, remark) {
|
|
1073
1476
|
await this.executeOpen("POST", "/api/open/topicUser/editRemark", { id, remark });
|
|
1074
1477
|
}
|
|
1478
|
+
/**
|
|
1479
|
+
* 4. 将订阅人加入黑名单。
|
|
1480
|
+
*
|
|
1481
|
+
* 加入后将移出群组,对方无法再加入该群组。积分群组不支持黑名单。不能将自己加入黑名单。
|
|
1482
|
+
*
|
|
1483
|
+
* @param topicRelationId 用户编号(订阅人列表中的 id 字段)
|
|
1484
|
+
*/
|
|
1485
|
+
async addBlacklist(topicRelationId) {
|
|
1486
|
+
const path = this.appendQuery("/api/open/topicUser/addBlacklist", { topicRelationId });
|
|
1487
|
+
await this.executeOpen("POST", path);
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* 5. 订阅人黑名单列表。
|
|
1491
|
+
*
|
|
1492
|
+
* `query.params.topicId` 必填。
|
|
1493
|
+
*/
|
|
1494
|
+
blacklistList(query) {
|
|
1495
|
+
return this.executeOpen(
|
|
1496
|
+
"POST",
|
|
1497
|
+
"/api/open/topicUser/blacklistList",
|
|
1498
|
+
query
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* 6. 解除订阅人黑名单。
|
|
1503
|
+
*
|
|
1504
|
+
* 解除后不会自动恢复群组订阅,对方可重新加入该群组。
|
|
1505
|
+
*
|
|
1506
|
+
* @param id 黑名单记录 ID(黑名单列表中的 id 字段)
|
|
1507
|
+
*/
|
|
1508
|
+
async removeBlacklist(id) {
|
|
1509
|
+
await this.executeOpen(
|
|
1510
|
+
"POST",
|
|
1511
|
+
this.appendQuery("/api/open/topicUser/removeBlacklist", { id })
|
|
1512
|
+
);
|
|
1513
|
+
}
|
|
1075
1514
|
};
|
|
1076
1515
|
|
|
1077
1516
|
// src/api/user-api.ts
|
|
@@ -1136,7 +1575,7 @@ function resolveConfig(input) {
|
|
|
1136
1575
|
logRequest: (_g = cfg.logRequest) != null ? _g : false,
|
|
1137
1576
|
rateLimitGuardEnabled: (_h = cfg.rateLimitGuardEnabled) != null ? _h : true,
|
|
1138
1577
|
rateLimitCooldownMs: (_i = cfg.rateLimitCooldownMs) != null ? _i : 0,
|
|
1139
|
-
userAgent: (_j = cfg.userAgent) != null ? _j : `@perk-net/perk-pushplus-sdk/1.
|
|
1578
|
+
userAgent: (_j = cfg.userAgent) != null ? _j : `@perk-net/perk-pushplus-sdk/1.2.1`
|
|
1140
1579
|
};
|
|
1141
1580
|
}
|
|
1142
1581
|
|
|
@@ -1231,6 +1670,9 @@ var PushPlusClient = class _PushPlusClient {
|
|
|
1231
1670
|
this.setting = new SettingApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1232
1671
|
this.pre = new PreApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1233
1672
|
this.image = new ImageApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1673
|
+
this.form = new FormApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1674
|
+
this.doc = new DocApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1675
|
+
this.excel = new ExcelApi(this.config, this.httpRequester, this.accessKeyManager);
|
|
1234
1676
|
}
|
|
1235
1677
|
/** 与 Java SDK 风格一致的 Builder 入口。 */
|
|
1236
1678
|
static builder() {
|
|
@@ -1464,6 +1906,6 @@ function batchSendRequest() {
|
|
|
1464
1906
|
return new BatchSendRequestBuilder();
|
|
1465
1907
|
}
|
|
1466
1908
|
|
|
1467
|
-
export { AbstractApi, AccessKeyApi, AccessKeyManager, BatchSendRequestBuilder, CallbackEvent, CallbackParser, Channel, ChannelApi, ClawBotApi, DEFAULT_BASE_URL, ErrorCode, FetchHttpRequester, FriendApi, ImageApi, MessageApi, MessageTokenApi, OpenAbstractApi, OpenMessageApi, PreApi, PushPlusClient, PushPlusClientBuilder, PushPlusError, PushPlusException, RateLimitGuard, SendRequestBuilder, SendStatus, SendStatusDescription, SettingApi, Template, TopicApi, TopicUserApi, UserApi, WebhookApi, WebhookType, WebhookTypeDescription, batchSendRequest, callExecuteRaw, errorCodeFromValue, isRateLimitedCode, isSuccessfulHttpStatus, parseCallback, resolveConfig, sendRequest };
|
|
1909
|
+
export { AbstractApi, AccessKeyApi, AccessKeyManager, BatchSendRequestBuilder, CallbackEvent, CallbackParser, Channel, ChannelApi, ClawBotApi, DEFAULT_BASE_URL, DocApi, ErrorCode, ExcelApi, FetchHttpRequester, FormApi, FormStatus, FormStatusDescription, FriendApi, ImageApi, MessageApi, MessageTokenApi, OpenAbstractApi, OpenMessageApi, PreApi, PushPlusClient, PushPlusClientBuilder, PushPlusError, PushPlusException, RateLimitGuard, SendRequestBuilder, SendStatus, SendStatusDescription, SettingApi, ShareLogin, SharePerm, Template, TopicApi, TopicUserApi, UserApi, WebhookApi, WebhookType, WebhookTypeDescription, batchSendRequest, callExecuteRaw, errorCodeFromValue, isRateLimitedCode, isSuccessfulHttpStatus, parseCallback, resolveConfig, sendRequest };
|
|
1468
1910
|
//# sourceMappingURL=index.js.map
|
|
1469
1911
|
//# sourceMappingURL=index.js.map
|