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