fishpi 0.0.4 → 0.0.8

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.
@@ -0,0 +1,31 @@
1
+ import { ApiResponse, NoticeCount, NoticeList } from './typing';
2
+ declare class Notice {
3
+ private _apiKey;
4
+ constructor(token?: string);
5
+ /**
6
+ * 重新设置请求 Token
7
+ * @param apiKey 接口 API Key
8
+ */
9
+ setToken(token: string): void;
10
+ /**
11
+ * 获取未读消息数
12
+ */
13
+ count(): Promise<NoticeCount>;
14
+ /**
15
+ * 获取消息列表
16
+ * @param type 消息类型
17
+ */
18
+ list(type: string): Promise<ApiResponse<NoticeList>>;
19
+ /**
20
+ * 已读指定类型消息
21
+ * @param type 消息类型
22
+ */
23
+ makeRead(type: string): Promise<ApiResponse<undefined>>;
24
+ /**
25
+ * 已读所有消息
26
+ */
27
+ readAll(): Promise<{
28
+ code: number;
29
+ }>;
30
+ }
31
+ export default Notice;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var utils_1 = require("./utils");
40
+ var Notice = /** @class */ (function () {
41
+ function Notice(token) {
42
+ if (token === void 0) { token = ''; }
43
+ this._apiKey = '';
44
+ if (!token) {
45
+ return;
46
+ }
47
+ this._apiKey = token;
48
+ }
49
+ /**
50
+ * 重新设置请求 Token
51
+ * @param apiKey 接口 API Key
52
+ */
53
+ Notice.prototype.setToken = function (token) {
54
+ this._apiKey = token;
55
+ };
56
+ /**
57
+ * 获取未读消息数
58
+ */
59
+ Notice.prototype.count = function () {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var rsp, e_1;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ _a.trys.push([0, 2, , 3]);
66
+ return [4 /*yield*/, (0, utils_1.request)({
67
+ url: "notifications/unread/count?apiKey=".concat(this._apiKey),
68
+ })];
69
+ case 1:
70
+ rsp = _a.sent();
71
+ rsp.data.userNotifyStatus = rsp.data.userNotifyStatus != 0;
72
+ return [2 /*return*/, rsp.data];
73
+ case 2:
74
+ e_1 = _a.sent();
75
+ throw e_1;
76
+ case 3: return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ };
81
+ /**
82
+ * 获取消息列表
83
+ * @param type 消息类型
84
+ */
85
+ Notice.prototype.list = function (type) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ var rsp, e_2;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ _a.trys.push([0, 2, , 3]);
92
+ return [4 /*yield*/, (0, utils_1.request)({
93
+ url: "api/getNotifications?apiKey=".concat(this._apiKey, "&type=").concat(type),
94
+ })];
95
+ case 1:
96
+ rsp = _a.sent();
97
+ return [2 /*return*/, rsp.data];
98
+ case 2:
99
+ e_2 = _a.sent();
100
+ throw e_2;
101
+ case 3: return [2 /*return*/];
102
+ }
103
+ });
104
+ });
105
+ };
106
+ /**
107
+ * 已读指定类型消息
108
+ * @param type 消息类型
109
+ */
110
+ Notice.prototype.makeRead = function (type) {
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ var rsp, e_3;
113
+ return __generator(this, function (_a) {
114
+ switch (_a.label) {
115
+ case 0:
116
+ _a.trys.push([0, 2, , 3]);
117
+ return [4 /*yield*/, (0, utils_1.request)({
118
+ url: "notifications/make-read/".concat(type, "?apiKey=").concat(this._apiKey),
119
+ })];
120
+ case 1:
121
+ rsp = _a.sent();
122
+ return [2 /*return*/, rsp.data];
123
+ case 2:
124
+ e_3 = _a.sent();
125
+ throw e_3;
126
+ case 3: return [2 /*return*/];
127
+ }
128
+ });
129
+ });
130
+ };
131
+ /**
132
+ * 已读所有消息
133
+ */
134
+ Notice.prototype.readAll = function () {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ var rsp, e_4;
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0:
140
+ _a.trys.push([0, 2, , 3]);
141
+ return [4 /*yield*/, (0, utils_1.request)({
142
+ url: "notifications/all-read?apiKey=".concat(this._apiKey),
143
+ })];
144
+ case 1:
145
+ rsp = _a.sent();
146
+ return [2 /*return*/, rsp.data];
147
+ case 2:
148
+ e_4 = _a.sent();
149
+ throw e_4;
150
+ case 3: return [2 /*return*/];
151
+ }
152
+ });
153
+ });
154
+ };
155
+ return Notice;
156
+ }());
157
+ exports.default = Notice;