@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.
Files changed (114) hide show
  1. package/AGENT.md +271 -0
  2. package/coverage/clover.xml +605 -0
  3. package/coverage/coverage-final.json +49 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +87 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +671 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +2 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +210 -0
  12. package/coverage/lcov.info +977 -0
  13. package/dist/esm/community-web/api/v1/short_code/encode.js +25 -0
  14. package/dist/esm/community-web/api/v1/short_code/shortcode.test.js +5 -0
  15. package/dist/esm/community-web/approval/approval.test.js +5 -0
  16. package/dist/esm/community-web/approval/list.js +16 -0
  17. package/dist/esm/community-web/base/dateTime.js +10 -0
  18. package/dist/esm/community-web/base/dateTime.test.js +6 -0
  19. package/dist/esm/community-web/campaign_resource/detail.js +12 -0
  20. package/dist/esm/community-web/campaign_resource/detail.test.js +10 -0
  21. package/dist/esm/community-web/check_in_record/check_in_record.test.js +8 -0
  22. package/dist/esm/community-web/check_in_record/detail.js +8 -0
  23. package/dist/esm/community-web/check_in_record/insert.js +12 -0
  24. package/dist/esm/community-web/cloud_asset/search.js +25 -0
  25. package/dist/esm/community-web/cloud_asset/search.test.js +6 -0
  26. package/dist/esm/community-web/cloud_asset/user/privacy.js +11 -0
  27. package/dist/esm/community-web/cloud_asset/user/privacy.test.js +4 -0
  28. package/dist/esm/community-web/comment/page.js +26 -0
  29. package/dist/esm/community-web/comment/page.test.js +15 -0
  30. package/dist/esm/community-web/comment/page_by_topic.js +26 -0
  31. package/dist/esm/community-web/comment/page_by_topic.test.js +13 -0
  32. package/dist/esm/community-web/config/detail.js +13 -0
  33. package/dist/esm/community-web/creation/creation.test.js +118 -0
  34. package/dist/esm/community-web/creation/detail.js +14 -0
  35. package/dist/esm/community-web/creation/excellent/list.js +13 -0
  36. package/dist/esm/community-web/creation/introduction/detail.js +13 -0
  37. package/dist/esm/community-web/creation/like/detail.js +13 -0
  38. package/dist/esm/community-web/creation/loading/tips.js +11 -0
  39. package/dist/esm/community-web/creation/page.js +24 -0
  40. package/dist/esm/community-web/creation/page_by_student.js +24 -0
  41. package/dist/esm/community-web/creation/potential/list.js +13 -0
  42. package/dist/esm/community-web/creation/recommend.js +23 -0
  43. package/dist/esm/community-web/creation/search/page.js +24 -0
  44. package/dist/esm/community-web/creation/student/detail.js +13 -0
  45. package/dist/esm/community-web/creation/tag/list.js +12 -0
  46. package/dist/esm/community-web/index.js +50 -0
  47. package/dist/esm/community-web/short_url/create.js +15 -0
  48. package/dist/esm/community-web/short_url/shortUrl.test.js +4 -0
  49. package/dist/esm/index.js +5 -2
  50. package/dist/esm/queryPages.js +22 -0
  51. package/dist/esm/sso/index.js +5 -3
  52. package/dist/esm/sso/web/auth/auth.test.js +13 -61
  53. package/dist/esm/sso/web/auth/login-by-password.js +25 -82
  54. package/dist/esm/sso/web/auth/logout.js +9 -48
  55. package/dist/esm/sso/web/auth/logout_by_session.js +12 -0
  56. package/dist/node/community-web/api/v1/short_code/encode.js +29 -0
  57. package/dist/node/community-web/api/v1/short_code/shortcode.test.js +7 -0
  58. package/dist/node/community-web/approval/approval.test.js +7 -0
  59. package/dist/node/community-web/approval/list.js +23 -0
  60. package/dist/node/community-web/base/dateTime.js +17 -0
  61. package/dist/node/community-web/base/dateTime.test.js +8 -0
  62. package/dist/node/community-web/campaign_resource/detail.js +16 -0
  63. package/dist/node/community-web/campaign_resource/detail.test.js +12 -0
  64. package/dist/node/community-web/check_in_record/check_in_record.test.js +10 -0
  65. package/dist/node/community-web/check_in_record/detail.js +12 -0
  66. package/dist/node/community-web/check_in_record/insert.js +16 -0
  67. package/dist/node/community-web/cloud_asset/search.js +29 -0
  68. package/dist/node/community-web/cloud_asset/search.test.js +8 -0
  69. package/dist/node/community-web/cloud_asset/user/privacy.js +15 -0
  70. package/dist/node/community-web/cloud_asset/user/privacy.test.js +6 -0
  71. package/dist/node/community-web/comment/page.js +30 -0
  72. package/dist/node/community-web/comment/page.test.js +17 -0
  73. package/dist/node/community-web/comment/page_by_topic.js +30 -0
  74. package/dist/node/community-web/comment/page_by_topic.test.js +15 -0
  75. package/dist/node/community-web/config/detail.js +17 -0
  76. package/dist/node/community-web/creation/creation.test.js +120 -0
  77. package/dist/node/community-web/creation/detail.js +18 -0
  78. package/dist/node/community-web/creation/excellent/list.js +17 -0
  79. package/dist/node/community-web/creation/introduction/detail.js +17 -0
  80. package/dist/node/community-web/creation/like/detail.js +17 -0
  81. package/dist/node/community-web/creation/loading/tips.js +15 -0
  82. package/dist/node/community-web/creation/page.js +28 -0
  83. package/dist/node/community-web/creation/page_by_student.js +28 -0
  84. package/dist/node/community-web/creation/potential/list.js +17 -0
  85. package/dist/node/community-web/creation/recommend.js +27 -0
  86. package/dist/node/community-web/creation/search/page.js +28 -0
  87. package/dist/node/community-web/creation/student/detail.js +17 -0
  88. package/dist/node/community-web/creation/tag/list.js +16 -0
  89. package/dist/node/community-web/index.js +53 -0
  90. package/dist/node/community-web/short_url/create.js +19 -0
  91. package/dist/node/community-web/short_url/shortUrl.test.js +6 -0
  92. package/dist/node/index.js +6 -2
  93. package/dist/node/queryPages.js +26 -0
  94. package/dist/node/sso/index.js +4 -2
  95. package/dist/node/sso/web/auth/auth.test.js +15 -63
  96. package/dist/node/sso/web/auth/login-by-password.js +25 -82
  97. package/dist/node/sso/web/auth/logout.js +9 -48
  98. package/dist/node/sso/web/auth/logout_by_session.js +16 -0
  99. package/package.json +7 -2
  100. package/tsconfig.json +5 -3
  101. package/dist/esm/types.js +0 -1
  102. package/dist/node/types.js +0 -2
  103. package/dist/types/index.d.ts +0 -10
  104. package/dist/types/sso/index.d.ts +0 -6
  105. package/dist/types/sso/web/auth/login-by-password.d.ts +0 -38
  106. package/dist/types/sso/web/auth/logout.d.ts +0 -3
  107. package/dist/types/types.d.ts +0 -17
  108. package/jest.config.ts +0 -13
  109. package/src/index.ts +0 -8
  110. package/src/sso/index.ts +0 -7
  111. package/src/sso/web/auth/auth.test.ts +0 -16
  112. package/src/sso/web/auth/login-by-password.ts +0 -58
  113. package/src/sso/web/auth/logout.ts +0 -9
  114. 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
- var login_by_password_1 = require("./login-by-password");
40
- var logout_1 = require("./logout");
41
- test("expect password to be error", function () { return __awaiter(void 0, void 0, void 0, function () {
42
- return __generator(this, function (_a) {
43
- switch (_a.label) {
44
- case 0: return [4 /*yield*/, expect(function () {
45
- return (0, login_by_password_1.loginByPassword)("abc", "foo", {
46
- device: "test",
47
- browser: "test",
48
- });
49
- }).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)")];
50
- case 1:
51
- _a.sent();
52
- return [2 /*return*/];
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
- var axios_1 = require("@ccw-api/axios");
5
+ const axios_1 = require("@ccw-api/axios");
64
6
  exports.url = "https://sso.ccw.site/web/auth/login-by-password";
65
- function loginByPassword(loginKey_1, password_1) {
66
- return __awaiter(this, arguments, void 0, function (loginKey, password, reqExtra) {
67
- var _a, _extra, rest;
68
- if (reqExtra === void 0) { reqExtra = {
69
- device: "Node",
70
- browser: "Node.js",
71
- }; }
72
- return __generator(this, function (_b) {
73
- switch (_b.label) {
74
- case 0: return [4 /*yield*/, axios_1.ccwAxios
75
- .post(exports.url, {
76
- loginKey: loginKey,
77
- password: password,
78
- clientCode: "STUDY_COMMUNITY",
79
- extra: JSON.stringify(__assign(__assign({}, reqExtra), { scene: null })),
80
- })
81
- .then(function (res) { return res.data.body; })];
82
- case 1:
83
- _a = _b.sent(), _extra = _a.extra, rest = __rest(_a, ["extra"]);
84
- return [2 /*return*/, __assign(__assign({}, rest), { extra: JSON.parse(_extra) })];
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
- var axios_1 = require("@ccw-api/axios");
5
+ const axios_1 = require("@ccw-api/axios");
42
6
  exports.url = "https://sso.ccw.site/web/auth/logout";
43
- function logout() {
44
- return __awaiter(this, void 0, void 0, function () {
45
- return __generator(this, function (_a) {
46
- switch (_a.label) {
47
- case 0: return [4 /*yield*/, axios_1.ccwAxios
48
- .post(exports.url, {})
49
- .then(function (res) { return res.data; })];
50
- case 1: return [2 /*return*/, _a.sent()];
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.1.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.1.2"
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": "src",
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 {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,6 +0,0 @@
1
- import { loginByPassword } from "./web/auth/login-by-password";
2
- import { logout } from "./web/auth/logout";
3
- export declare const sso: {
4
- loginByPassword: typeof loginByPassword;
5
- logout: typeof logout;
6
- };
@@ -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 {};
@@ -1,3 +0,0 @@
1
- import { ApiResponse } from "../../../types";
2
- export declare const url = "https://sso.ccw.site/web/auth/logout";
3
- export declare function logout(): Promise<ApiResponse<null>>;
@@ -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
@@ -1,8 +0,0 @@
1
- import { sso } from "./sso/index";
2
- export type * from "./types";
3
-
4
- export { sso };
5
-
6
- export default {
7
- sso,
8
- };
package/src/sso/index.ts DELETED
@@ -1,7 +0,0 @@
1
- import { loginByPassword } from "./web/auth/login-by-password";
2
- import { logout } from "./web/auth/logout";
3
-
4
- export const sso = {
5
- loginByPassword,
6
- logout,
7
- };
@@ -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
- };