@ccw-api/api 0.1.0 → 0.3.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/AGENT.md +271 -0
- package/coverage/clover.xml +605 -0
- package/coverage/coverage-final.json +49 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +671 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +977 -0
- package/dist/esm/community-web/api/v1/short_code/encode.js +25 -0
- package/dist/esm/community-web/api/v1/short_code/shortcode.test.js +5 -0
- package/dist/esm/community-web/approval/approval.test.js +5 -0
- package/dist/esm/community-web/approval/list.js +16 -0
- package/dist/esm/community-web/base/dateTime.js +10 -0
- package/dist/esm/community-web/base/dateTime.test.js +6 -0
- package/dist/esm/community-web/campaign_resource/detail.js +12 -0
- package/dist/esm/community-web/campaign_resource/detail.test.js +10 -0
- package/dist/esm/community-web/check_in_record/check_in_record.test.js +8 -0
- package/dist/esm/community-web/check_in_record/detail.js +8 -0
- package/dist/esm/community-web/check_in_record/insert.js +12 -0
- package/dist/esm/community-web/cloud_asset/search.js +25 -0
- package/dist/esm/community-web/cloud_asset/search.test.js +6 -0
- package/dist/esm/community-web/cloud_asset/user/privacy.js +11 -0
- package/dist/esm/community-web/cloud_asset/user/privacy.test.js +4 -0
- package/dist/esm/community-web/comment/page.js +26 -0
- package/dist/esm/community-web/comment/page.test.js +15 -0
- package/dist/esm/community-web/comment/page_by_topic.js +26 -0
- package/dist/esm/community-web/comment/page_by_topic.test.js +13 -0
- package/dist/esm/community-web/config/detail.js +13 -0
- package/dist/esm/community-web/creation/creation.test.js +118 -0
- package/dist/esm/community-web/creation/detail.js +14 -0
- package/dist/esm/community-web/creation/excellent/list.js +13 -0
- package/dist/esm/community-web/creation/introduction/detail.js +13 -0
- package/dist/esm/community-web/creation/like/detail.js +13 -0
- package/dist/esm/community-web/creation/loading/tips.js +11 -0
- package/dist/esm/community-web/creation/page.js +24 -0
- package/dist/esm/community-web/creation/page_by_student.js +24 -0
- package/dist/esm/community-web/creation/potential/list.js +13 -0
- package/dist/esm/community-web/creation/recommend.js +23 -0
- package/dist/esm/community-web/creation/search/page.js +24 -0
- package/dist/esm/community-web/creation/student/detail.js +13 -0
- package/dist/esm/community-web/creation/tag/list.js +12 -0
- package/dist/esm/community-web/index.js +50 -0
- package/dist/esm/community-web/short_url/create.js +15 -0
- package/dist/esm/community-web/short_url/shortUrl.test.js +4 -0
- package/dist/esm/index.js +5 -2
- package/dist/esm/queryPages.js +22 -0
- package/dist/esm/sso/index.js +5 -3
- package/dist/esm/sso/web/auth/auth.test.js +13 -61
- package/dist/esm/sso/web/auth/login-by-password.js +25 -82
- package/dist/esm/sso/web/auth/logout.js +9 -48
- package/dist/esm/sso/web/auth/logout_by_session.js +12 -0
- package/dist/node/community-web/api/v1/short_code/encode.js +29 -0
- package/dist/node/community-web/api/v1/short_code/shortcode.test.js +7 -0
- package/dist/node/community-web/approval/approval.test.js +7 -0
- package/dist/node/community-web/approval/list.js +23 -0
- package/dist/node/community-web/base/dateTime.js +17 -0
- package/dist/node/community-web/base/dateTime.test.js +8 -0
- package/dist/node/community-web/campaign_resource/detail.js +16 -0
- package/dist/node/community-web/campaign_resource/detail.test.js +12 -0
- package/dist/node/community-web/check_in_record/check_in_record.test.js +10 -0
- package/dist/node/community-web/check_in_record/detail.js +12 -0
- package/dist/node/community-web/check_in_record/insert.js +16 -0
- package/dist/node/community-web/cloud_asset/search.js +29 -0
- package/dist/node/community-web/cloud_asset/search.test.js +8 -0
- package/dist/node/community-web/cloud_asset/user/privacy.js +15 -0
- package/dist/node/community-web/cloud_asset/user/privacy.test.js +6 -0
- package/dist/node/community-web/comment/page.js +30 -0
- package/dist/node/community-web/comment/page.test.js +17 -0
- package/dist/node/community-web/comment/page_by_topic.js +30 -0
- package/dist/node/community-web/comment/page_by_topic.test.js +15 -0
- package/dist/node/community-web/config/detail.js +17 -0
- package/dist/node/community-web/creation/creation.test.js +120 -0
- package/dist/node/community-web/creation/detail.js +18 -0
- package/dist/node/community-web/creation/excellent/list.js +17 -0
- package/dist/node/community-web/creation/introduction/detail.js +17 -0
- package/dist/node/community-web/creation/like/detail.js +17 -0
- package/dist/node/community-web/creation/loading/tips.js +15 -0
- package/dist/node/community-web/creation/page.js +28 -0
- package/dist/node/community-web/creation/page_by_student.js +28 -0
- package/dist/node/community-web/creation/potential/list.js +17 -0
- package/dist/node/community-web/creation/recommend.js +27 -0
- package/dist/node/community-web/creation/search/page.js +28 -0
- package/dist/node/community-web/creation/student/detail.js +17 -0
- package/dist/node/community-web/creation/tag/list.js +16 -0
- package/dist/node/community-web/index.js +53 -0
- package/dist/node/community-web/short_url/create.js +19 -0
- package/dist/node/community-web/short_url/shortUrl.test.js +6 -0
- package/dist/node/index.js +6 -2
- package/dist/node/queryPages.js +26 -0
- package/dist/node/sso/index.js +4 -2
- package/dist/node/sso/web/auth/auth.test.js +15 -63
- package/dist/node/sso/web/auth/login-by-password.js +25 -82
- package/dist/node/sso/web/auth/logout.js +9 -48
- package/dist/node/sso/web/auth/logout_by_session.js +16 -0
- package/package.json +7 -2
- package/tsconfig.json +5 -3
- package/dist/esm/types.js +0 -1
- package/dist/node/types.js +0 -2
- package/dist/types/index.d.ts +0 -10
- package/dist/types/sso/index.d.ts +0 -6
- package/dist/types/sso/web/auth/login-by-password.d.ts +0 -38
- package/dist/types/sso/web/auth/logout.d.ts +0 -3
- package/dist/types/types.d.ts +0 -17
- package/jest.config.ts +0 -13
- package/src/index.ts +0 -8
- package/src/sso/index.ts +0 -7
- package/src/sso/web/auth/auth.test.ts +0 -16
- package/src/sso/web/auth/login-by-password.ts +0 -58
- package/src/sso/web/auth/logout.ts +0 -9
- package/src/types.ts +0 -18
|
@@ -1,65 +1,17 @@
|
|
|
1
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}); });
|
|
56
|
-
test("expect logout to be error when no token", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
57
|
-
return __generator(this, function (_a) {
|
|
58
|
-
switch (_a.label) {
|
|
59
|
-
case 0: return [4 /*yield*/, expect(logout_1.logout).rejects.toThrow("ccw axios Request failed: token不能为空(4001092X01)")];
|
|
60
|
-
case 1:
|
|
61
|
-
_a.sent();
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}); });
|
|
3
|
+
const login_by_password_1 = require("./login-by-password");
|
|
4
|
+
const logout_1 = require("./logout");
|
|
5
|
+
const logout_by_session_1 = require("./logout_by_session");
|
|
6
|
+
test("expect wrong password to be error", async () => {
|
|
7
|
+
await expect(async () => await (0, login_by_password_1.loginByPassword)("abc", "foo", {
|
|
8
|
+
device: "test",
|
|
9
|
+
browser: "test",
|
|
10
|
+
})).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)");
|
|
11
|
+
});
|
|
12
|
+
test("expect logout to be error when no token", async () => {
|
|
13
|
+
await expect(logout_1.logout).rejects.toThrow("ccw axios Request failed: token不能为空(4001092X01)");
|
|
14
|
+
});
|
|
15
|
+
test("expect logout-by-session to be error when not logged in", async () => {
|
|
16
|
+
await expect(async () => await (0, logout_by_session_1.logoutBySession)(1145)).rejects.toThrow("ccw axios Request failed: 用户未登录(4001092401)");
|
|
17
|
+
});
|
|
@@ -1,88 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
-
var t = {};
|
|
51
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
-
t[p] = s[p];
|
|
53
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
-
t[p[i]] = s[p[i]];
|
|
57
|
-
}
|
|
58
|
-
return t;
|
|
59
|
-
};
|
|
60
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
3
|
exports.url = void 0;
|
|
62
4
|
exports.loginByPassword = loginByPassword;
|
|
63
|
-
|
|
5
|
+
const axios_1 = require("@ccw-api/axios");
|
|
64
6
|
exports.url = "https://sso.ccw.site/web/auth/login-by-password";
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
7
|
+
/**
|
|
8
|
+
* 通过密码登录
|
|
9
|
+
* @param {string} loginKey 用户名
|
|
10
|
+
* @param {string} password 密码
|
|
11
|
+
* @param {ReqExtra} reqExtra 额外信息
|
|
12
|
+
* @returns {Res<Extra>}
|
|
13
|
+
*/
|
|
14
|
+
async function loginByPassword(loginKey, password, reqExtra = {
|
|
15
|
+
device: "Node",
|
|
16
|
+
browser: "Node.js",
|
|
17
|
+
}) {
|
|
18
|
+
const { extra, ...restBody } = await axios_1.ccwAxios
|
|
19
|
+
.post(exports.url, {
|
|
20
|
+
loginKey,
|
|
21
|
+
password,
|
|
22
|
+
clientCode: "STUDY_COMMUNITY",
|
|
23
|
+
extra: JSON.stringify({ ...reqExtra, scene: null }),
|
|
24
|
+
})
|
|
25
|
+
.then((res) => res.data.body);
|
|
26
|
+
const resExtra = JSON.parse(extra);
|
|
27
|
+
return {
|
|
28
|
+
...restBody,
|
|
29
|
+
extra: resExtra,
|
|
30
|
+
};
|
|
88
31
|
}
|
|
@@ -1,54 +1,15 @@
|
|
|
1
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.url = void 0;
|
|
40
4
|
exports.logout = logout;
|
|
41
|
-
|
|
5
|
+
const axios_1 = require("@ccw-api/axios");
|
|
42
6
|
exports.url = "https://sso.ccw.site/web/auth/logout";
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
7
|
+
/**
|
|
8
|
+
* 退出
|
|
9
|
+
* @returns {Promise<null>}
|
|
10
|
+
*/
|
|
11
|
+
async function logout() {
|
|
12
|
+
return await axios_1.ccwAxios
|
|
13
|
+
.post(exports.url, {})
|
|
14
|
+
.then((res) => res.data.body);
|
|
54
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.url = void 0;
|
|
4
|
+
exports.logoutBySession = logoutBySession;
|
|
5
|
+
const axios_1 = require("@ccw-api/axios");
|
|
6
|
+
exports.url = "https://sso.ccw.site/web/auth/logout_by_session";
|
|
7
|
+
/**
|
|
8
|
+
* 根据sessionId退出登陆设备
|
|
9
|
+
* @param {number} sessionId
|
|
10
|
+
* @returns {Promise<boolean>} 是否成功
|
|
11
|
+
*/
|
|
12
|
+
async function logoutBySession(sessionId) {
|
|
13
|
+
return await axios_1.ccwAxios
|
|
14
|
+
.post(exports.url, { id: sessionId })
|
|
15
|
+
.then((res) => res.data.body);
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ccw-api/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "ccw api collections",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Meng Fuzi",
|
|
7
|
+
"homepage": "https://schale.qzz.io/ccw-api-api/",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"main": "dist/node/index.js",
|
|
9
10
|
"module": "dist/esm/index.js",
|
|
@@ -18,6 +19,9 @@
|
|
|
18
19
|
"scripts": {
|
|
19
20
|
"prepublishOnly": "npm run build && npm test",
|
|
20
21
|
"test": "jest",
|
|
22
|
+
"test:dev": "jest --watch",
|
|
23
|
+
"doc": "typedoc",
|
|
24
|
+
"doc:dev": "typedoc --watch",
|
|
21
25
|
"build": "tsc --project tsconfig.node.json && tsc --project tsconfig.esm.json && tsc --project tsconfig.types.json"
|
|
22
26
|
},
|
|
23
27
|
"dependencies": {
|
|
@@ -27,6 +31,7 @@
|
|
|
27
31
|
"@types/jest": "^30.0.0",
|
|
28
32
|
"@types/node": "^26.0.1",
|
|
29
33
|
"jest": "^30.4.2",
|
|
30
|
-
"ts-jest": "^29.
|
|
34
|
+
"ts-jest": "^29.4.11",
|
|
35
|
+
"typedoc": "^0.28.19"
|
|
31
36
|
}
|
|
32
37
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"declaration": true,
|
|
4
|
-
"rootDir": "
|
|
4
|
+
"rootDir": ".",
|
|
5
5
|
"outDir": "dist",
|
|
6
6
|
"types": ["jest", "node"],
|
|
7
7
|
"esModuleInterop": true,
|
|
8
8
|
"module": "esnext",
|
|
9
|
-
"moduleResolution": "bundler"
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"target": "esnext",
|
|
11
|
+
"baseUrl": "."
|
|
10
12
|
},
|
|
11
|
-
"include": ["src"]
|
|
13
|
+
"include": ["src", "types"]
|
|
12
14
|
}
|
package/dist/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/node/types.js
DELETED
package/dist/types/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { sso } from "./sso/index";
|
|
2
|
-
export type * from "./types";
|
|
3
|
-
export { sso };
|
|
4
|
-
declare const _default: {
|
|
5
|
-
sso: {
|
|
6
|
-
loginByPassword: typeof import("./sso/web/auth/login-by-password").loginByPassword;
|
|
7
|
-
logout: typeof import("./sso/web/auth/logout").logout;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export default _default;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, MongoDBId } from "../../../types";
|
|
2
|
-
export declare const url = "https://sso.ccw.site/web/auth/login-by-password";
|
|
3
|
-
export type Req = {
|
|
4
|
-
loginKey: string;
|
|
5
|
-
clientCode: "STUDY_COMMUNITY";
|
|
6
|
-
password: string;
|
|
7
|
-
extra: string;
|
|
8
|
-
};
|
|
9
|
-
export type Res<Extra = string> = ApiResponse<{
|
|
10
|
-
accountId: -1;
|
|
11
|
-
accountObjectId: MongoDBId;
|
|
12
|
-
accountType: "STUDENT";
|
|
13
|
-
clientCode: "STUDY_COMMUNITY";
|
|
14
|
-
createdAt: number;
|
|
15
|
-
email: null;
|
|
16
|
-
expireTime: number;
|
|
17
|
-
extra: Extra;
|
|
18
|
-
id: number;
|
|
19
|
-
lastAccessTime: number;
|
|
20
|
-
orgId: "";
|
|
21
|
-
scene: null;
|
|
22
|
-
status: "ENABLED";
|
|
23
|
-
token: string;
|
|
24
|
-
urlEncodedFullName: null;
|
|
25
|
-
}>;
|
|
26
|
-
type Extra = {
|
|
27
|
-
loginType: "BY_PASSWORD";
|
|
28
|
-
browser: string;
|
|
29
|
-
ip: string;
|
|
30
|
-
loginParentOid: MongoDBId;
|
|
31
|
-
device: string;
|
|
32
|
-
orgId: "";
|
|
33
|
-
};
|
|
34
|
-
export declare function loginByPassword(loginKey: string, password: string, reqExtra?: {
|
|
35
|
-
device: string;
|
|
36
|
-
browser: string;
|
|
37
|
-
}): Promise<Res<Extra>["body"]>;
|
|
38
|
-
export {};
|
package/dist/types/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 十六进制秒级时间戳
|
|
3
|
-
* @example const date = new Date(Number.parseInt(t, 16) * 1000);
|
|
4
|
-
*/
|
|
5
|
-
export type HexSecTimeStamp = string;
|
|
6
|
-
/**
|
|
7
|
-
* @example
|
|
8
|
-
* const t = id.subString(0,8);
|
|
9
|
-
* const date = new Date(Number.parseInt(t, 16) * 1000);
|
|
10
|
-
*/
|
|
11
|
-
export type MongoDBId = `${HexSecTimeStamp}${string}`;
|
|
12
|
-
export type ApiResponse<T> = {
|
|
13
|
-
body: T;
|
|
14
|
-
code: string;
|
|
15
|
-
msg: string;
|
|
16
|
-
status: number;
|
|
17
|
-
};
|
package/jest.config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Config } from "jest";
|
|
2
|
-
const config: Config = {
|
|
3
|
-
preset: "ts-jest",
|
|
4
|
-
testEnvironment: "node",
|
|
5
|
-
moduleFileExtensions: ["ts", "js", "json"],
|
|
6
|
-
collectCoverageFrom: [
|
|
7
|
-
"src/**/*.ts",
|
|
8
|
-
"!src/**/*.d.ts", // 排除类型声明文件
|
|
9
|
-
],
|
|
10
|
-
testMatch: ["**/src/**/*.test.ts"],
|
|
11
|
-
transformIgnorePatterns: [],
|
|
12
|
-
};
|
|
13
|
-
export default config;
|
package/src/index.ts
DELETED
package/src/sso/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { loginByPassword } from "./login-by-password";
|
|
2
|
-
import { logout } from "./logout";
|
|
3
|
-
test("expect password to be error", async () => {
|
|
4
|
-
await expect(() =>
|
|
5
|
-
loginByPassword("abc", "foo", {
|
|
6
|
-
device: "test",
|
|
7
|
-
browser: "test",
|
|
8
|
-
}),
|
|
9
|
-
).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test("expect logout to be error when no token", async () => {
|
|
13
|
-
await expect(logout).rejects.toThrow(
|
|
14
|
-
"ccw axios Request failed: token不能为空(4001092X01)",
|
|
15
|
-
);
|
|
16
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ccwAxios } from "@ccw-api/axios";
|
|
2
|
-
import { ApiResponse, MongoDBId } from "../../../types";
|
|
3
|
-
export const url = "https://sso.ccw.site/web/auth/login-by-password";
|
|
4
|
-
|
|
5
|
-
export type Req = {
|
|
6
|
-
loginKey: string;
|
|
7
|
-
clientCode: "STUDY_COMMUNITY";
|
|
8
|
-
password: string;
|
|
9
|
-
extra: string;
|
|
10
|
-
};
|
|
11
|
-
export type Res<Extra = string> = ApiResponse<{
|
|
12
|
-
accountId: -1;
|
|
13
|
-
accountObjectId: MongoDBId;
|
|
14
|
-
accountType: "STUDENT";
|
|
15
|
-
clientCode: "STUDY_COMMUNITY";
|
|
16
|
-
createdAt: number;
|
|
17
|
-
email: null;
|
|
18
|
-
expireTime: number;
|
|
19
|
-
extra: Extra;
|
|
20
|
-
id: number;
|
|
21
|
-
lastAccessTime: number;
|
|
22
|
-
orgId: "";
|
|
23
|
-
scene: null;
|
|
24
|
-
status: "ENABLED";
|
|
25
|
-
token: string;
|
|
26
|
-
urlEncodedFullName: null;
|
|
27
|
-
}>;
|
|
28
|
-
|
|
29
|
-
type Extra = {
|
|
30
|
-
loginType: "BY_PASSWORD";
|
|
31
|
-
browser: string;
|
|
32
|
-
ip: string;
|
|
33
|
-
loginParentOid: MongoDBId;
|
|
34
|
-
device: string;
|
|
35
|
-
orgId: "";
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export async function loginByPassword(
|
|
39
|
-
loginKey: string,
|
|
40
|
-
password: string,
|
|
41
|
-
reqExtra: { device: string; browser: string } = {
|
|
42
|
-
device: "Node",
|
|
43
|
-
browser: "Node.js",
|
|
44
|
-
},
|
|
45
|
-
): Promise<Res<Extra>["body"]> {
|
|
46
|
-
const { extra: _extra, ...rest } = await ccwAxios
|
|
47
|
-
.post<Res>(url, {
|
|
48
|
-
loginKey,
|
|
49
|
-
password,
|
|
50
|
-
clientCode: "STUDY_COMMUNITY",
|
|
51
|
-
extra: JSON.stringify({ ...reqExtra, scene: null }),
|
|
52
|
-
} satisfies Req)
|
|
53
|
-
.then((res) => res.data.body);
|
|
54
|
-
return {
|
|
55
|
-
...rest,
|
|
56
|
-
extra: JSON.parse(_extra),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ccwAxios } from "@ccw-api/axios";
|
|
2
|
-
import { ApiResponse } from "../../../types";
|
|
3
|
-
export const url = "https://sso.ccw.site/web/auth/logout";
|
|
4
|
-
|
|
5
|
-
export async function logout() {
|
|
6
|
-
return await ccwAxios
|
|
7
|
-
.post<ApiResponse<null>>(url, {})
|
|
8
|
-
.then((res) => res.data);
|
|
9
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 十六进制秒级时间戳
|
|
3
|
-
* @example const date = new Date(Number.parseInt(t, 16) * 1000);
|
|
4
|
-
*/
|
|
5
|
-
export type HexSecTimeStamp = string;
|
|
6
|
-
/**
|
|
7
|
-
* @example
|
|
8
|
-
* const t = id.subString(0,8);
|
|
9
|
-
* const date = new Date(Number.parseInt(t, 16) * 1000);
|
|
10
|
-
*/
|
|
11
|
-
export type MongoDBId = `${HexSecTimeStamp}${string}`;
|
|
12
|
-
|
|
13
|
-
export type ApiResponse<T> = {
|
|
14
|
-
body: T;
|
|
15
|
-
code: string;
|
|
16
|
-
msg: string;
|
|
17
|
-
status: number;
|
|
18
|
-
};
|