@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
@@ -0,0 +1,50 @@
1
+ import { encodeShortCode } from "./api/v1/short_code/encode";
2
+ import { getApprovalTags } from "./approval/list";
3
+ import { getTime } from "./base/dateTime";
4
+ import { getCampaignResources } from "./campaign_resource/detail";
5
+ import { getCheckInRecords } from "./check_in_record/detail";
6
+ import { insertCheckInRecord } from "./check_in_record/insert";
7
+ import { getUserAssetStorageSize } from "./cloud_asset/user/privacy";
8
+ import { searchCloudAssets } from "./cloud_asset/search";
9
+ import { getCommentReplies } from "./comment/page";
10
+ import { getCommentsByTopic } from "./comment/page_by_topic";
11
+ import { getConfigDetail } from "./config/detail";
12
+ import { getCreationDetail } from "./creation/detail";
13
+ import { getExcellentCreations } from "./creation/excellent/list";
14
+ import { getCreationIntroduction } from "./creation/introduction/detail";
15
+ import { getLikeDetail } from "./creation/like/detail";
16
+ import { getLoadingTips } from "./creation/loading/tips";
17
+ import { getCreationPage } from "./creation/page";
18
+ import { getCreationsByStudent } from "./creation/page_by_student";
19
+ import { getPotentialCreations } from "./creation/potential/list";
20
+ import { getRecommendCreations } from "./creation/recommend";
21
+ import { searchCreationsByTag } from "./creation/search/page";
22
+ import { getCreationStudentDetail } from "./creation/student/detail";
23
+ import { getCreationTags } from "./creation/tag/list";
24
+ import { createShortUrl } from "./short_url/create";
25
+ export const communityWeb = {
26
+ encodeShortCode,
27
+ createShortUrl,
28
+ getApprovalTags,
29
+ getCampaignResources,
30
+ getCheckInRecords,
31
+ getCommentReplies,
32
+ getCommentsByTopic,
33
+ getConfigDetail,
34
+ getCreationDetail,
35
+ getCreationIntroduction,
36
+ getCreationPage,
37
+ getCreationStudentDetail,
38
+ getCreationTags,
39
+ getCreationsByStudent,
40
+ getExcellentCreations,
41
+ getLikeDetail,
42
+ getLoadingTips,
43
+ getPotentialCreations,
44
+ getRecommendCreations,
45
+ getUserAssetStorageSize,
46
+ insertCheckInRecord,
47
+ searchCloudAssets,
48
+ searchCreationsByTag,
49
+ getTime,
50
+ };
@@ -0,0 +1,15 @@
1
+ import { ccwAxios } from "@ccw-api/axios";
2
+ export const url = "https://community-web.ccw.site/short_url/create";
3
+ /**
4
+ * 创建短链接(用于分享)
5
+ * @param originUrl 原链接
6
+ * @returns {Promise<Res>} 创建的短链接
7
+ */
8
+ export async function createShortUrl(originUrl) {
9
+ const req = {
10
+ originUrl,
11
+ };
12
+ return await ccwAxios
13
+ .post(url, req)
14
+ .then((res) => res.data.body);
15
+ }
@@ -0,0 +1,4 @@
1
+ import { createShortUrl } from "./create";
2
+ test("create short url", async () => {
3
+ expect(await createShortUrl("https://www.ccw.site/detail/6386e11cfc1ed14684de07f8?inviteCode=yZdXmD3PvwVPA30W")).toEqual("https://ccw.site/s/1Wr61k");
4
+ });
package/dist/esm/index.js CHANGED
@@ -1,5 +1,8 @@
1
+ /// <reference path="../types/types.d.ts">
1
2
  import { sso } from "./sso/index";
2
- export { sso };
3
+ import { communityWeb } from "./community-web";
4
+ export { sso, communityWeb };
3
5
  export default {
4
- sso: sso,
6
+ sso,
7
+ communityWeb,
5
8
  };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 生成ccw分页查询url
3
+ * @param url_ 分页查询api
4
+ * @param {PageArgs} pageArgs 分页参数
5
+ * @returns 生成的实际查询url
6
+ */
7
+ export function queryPage(url_, pageArgs) {
8
+ const url = new URL(url_);
9
+ Object.entries(pageArgs).forEach(([k, v]) => {
10
+ if (v == null) {
11
+ return;
12
+ }
13
+ url.searchParams.set(k, v);
14
+ });
15
+ return url.toString();
16
+ }
17
+ export const DEFAULT_PAGE_ARGS = {
18
+ page: 1,
19
+ perPage: 20,
20
+ sortType: "DESC",
21
+ sortField: "",
22
+ };
@@ -1,6 +1,8 @@
1
1
  import { loginByPassword } from "./web/auth/login-by-password";
2
2
  import { logout } from "./web/auth/logout";
3
- export var sso = {
4
- loginByPassword: loginByPassword,
5
- logout: logout,
3
+ import { logoutBySession } from "./web/auth/logout_by_session";
4
+ export const sso = {
5
+ loginByPassword,
6
+ logout,
7
+ logoutBySession,
6
8
  };
@@ -1,63 +1,15 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- 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);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- 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;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { loginByPassword } from "./login-by-password";
38
2
  import { logout } from "./logout";
39
- test("expect password to be error", function () { return __awaiter(void 0, void 0, void 0, function () {
40
- return __generator(this, function (_a) {
41
- switch (_a.label) {
42
- case 0: return [4 /*yield*/, expect(function () {
43
- return loginByPassword("abc", "foo", {
44
- device: "test",
45
- browser: "test",
46
- });
47
- }).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)")];
48
- case 1:
49
- _a.sent();
50
- return [2 /*return*/];
51
- }
52
- });
53
- }); });
54
- test("expect logout to be error when no token", function () { return __awaiter(void 0, void 0, void 0, function () {
55
- return __generator(this, function (_a) {
56
- switch (_a.label) {
57
- case 0: return [4 /*yield*/, expect(logout).rejects.toThrow("ccw axios Request failed: token不能为空(4001092X01)")];
58
- case 1:
59
- _a.sent();
60
- return [2 /*return*/];
61
- }
62
- });
63
- }); });
3
+ import { logoutBySession } from "./logout_by_session";
4
+ test("expect wrong password to be error", async () => {
5
+ await expect(async () => await loginByPassword("abc", "foo", {
6
+ device: "test",
7
+ browser: "test",
8
+ })).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)");
9
+ });
10
+ test("expect logout to be error when no token", async () => {
11
+ await expect(logout).rejects.toThrow("ccw axios Request failed: token不能为空(4001092X01)");
12
+ });
13
+ test("expect logout-by-session to be error when not logged in", async () => {
14
+ await expect(async () => await logoutBySession(1145)).rejects.toThrow("ccw axios Request failed: 用户未登录(4001092401)");
15
+ });
@@ -1,84 +1,27 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- 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);
23
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- 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;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- };
59
1
  import { ccwAxios } from "@ccw-api/axios";
60
- export var url = "https://sso.ccw.site/web/auth/login-by-password";
61
- export function loginByPassword(loginKey_1, password_1) {
62
- return __awaiter(this, arguments, void 0, function (loginKey, password, reqExtra) {
63
- var _a, _extra, rest;
64
- if (reqExtra === void 0) { reqExtra = {
65
- device: "Node",
66
- browser: "Node.js",
67
- }; }
68
- return __generator(this, function (_b) {
69
- switch (_b.label) {
70
- case 0: return [4 /*yield*/, ccwAxios
71
- .post(url, {
72
- loginKey: loginKey,
73
- password: password,
74
- clientCode: "STUDY_COMMUNITY",
75
- extra: JSON.stringify(__assign(__assign({}, reqExtra), { scene: null })),
76
- })
77
- .then(function (res) { return res.data.body; })];
78
- case 1:
79
- _a = _b.sent(), _extra = _a.extra, rest = __rest(_a, ["extra"]);
80
- return [2 /*return*/, __assign(__assign({}, rest), { extra: JSON.parse(_extra) })];
81
- }
82
- });
83
- });
2
+ export const url = "https://sso.ccw.site/web/auth/login-by-password";
3
+ /**
4
+ * 通过密码登录
5
+ * @param {string} loginKey 用户名
6
+ * @param {string} password 密码
7
+ * @param {ReqExtra} reqExtra 额外信息
8
+ * @returns {Res<Extra>}
9
+ */
10
+ export async function loginByPassword(loginKey, password, reqExtra = {
11
+ device: "Node",
12
+ browser: "Node.js",
13
+ }) {
14
+ const { extra, ...restBody } = await ccwAxios
15
+ .post(url, {
16
+ loginKey,
17
+ password,
18
+ clientCode: "STUDY_COMMUNITY",
19
+ extra: JSON.stringify({ ...reqExtra, scene: null }),
20
+ })
21
+ .then((res) => res.data.body);
22
+ const resExtra = JSON.parse(extra);
23
+ return {
24
+ ...restBody,
25
+ extra: resExtra,
26
+ };
84
27
  }
@@ -1,50 +1,11 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- 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);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- 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;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { ccwAxios } from "@ccw-api/axios";
38
- export var url = "https://sso.ccw.site/web/auth/logout";
39
- export function logout() {
40
- return __awaiter(this, void 0, void 0, function () {
41
- return __generator(this, function (_a) {
42
- switch (_a.label) {
43
- case 0: return [4 /*yield*/, ccwAxios
44
- .post(url, {})
45
- .then(function (res) { return res.data; })];
46
- case 1: return [2 /*return*/, _a.sent()];
47
- }
48
- });
49
- });
2
+ export const url = "https://sso.ccw.site/web/auth/logout";
3
+ /**
4
+ * 退出
5
+ * @returns {Promise<null>}
6
+ */
7
+ export async function logout() {
8
+ return await ccwAxios
9
+ .post(url, {})
10
+ .then((res) => res.data.body);
50
11
  }
@@ -0,0 +1,12 @@
1
+ import { ccwAxios } from "@ccw-api/axios";
2
+ export const url = "https://sso.ccw.site/web/auth/logout_by_session";
3
+ /**
4
+ * 根据sessionId退出登陆设备
5
+ * @param {number} sessionId
6
+ * @returns {Promise<boolean>} 是否成功
7
+ */
8
+ export async function logoutBySession(sessionId) {
9
+ return await ccwAxios
10
+ .post(url, { id: sessionId })
11
+ .then((res) => res.data.body);
12
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.url = void 0;
4
+ exports.encodeShortCode = encodeShortCode;
5
+ const axios_1 = require("@ccw-api/axios");
6
+ exports.url = "https://community-web.ccw.site/api/v1/short_code/encode";
7
+ /**
8
+ * 生成作品邀请码
9
+ * @param {MongoDBId} inviterId 邀请人id
10
+ * @param {CachedOssUrl} inviterAvatar 邀请人头像
11
+ * @param {string} inviterName 邀请人用户名
12
+ * @param {MongoDBId} creationOid 作品id
13
+ * @returns {Promise<Res>}
14
+ */
15
+ async function encodeShortCode(inviterId, inviterAvatar, inviterName, creationOid) {
16
+ const req = {
17
+ origin: {
18
+ inviterAvatar,
19
+ inviterName,
20
+ inviterId,
21
+ inviterType: "STUDENT",
22
+ entrance: "create_detail",
23
+ creationOid,
24
+ },
25
+ };
26
+ return await axios_1.ccwAxios
27
+ .post(exports.url, req)
28
+ .then((res) => res.data.body);
29
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const encode_1 = require("./encode");
4
+ test("test shortcode", async () => {
5
+ const res = await (0, encode_1.encodeShortCode)("63c2807d669fa967f17f5559", "https://m.ccw.site/user_projects_assets/244373873/3fc7886d05aed9f369d2c0bb2d677fc0.jpeg", "孟夫子驾到", "6386e11cfc1ed14684de07f8");
6
+ expect(res.code).toHaveLength("yZdXmD3PvwVPA30W".length);
7
+ });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const list_1 = require("./list");
4
+ test("test approval list", async () => {
5
+ const tags = await (0, list_1.getApprovalTags)("63c2807d669fa967f17f5559");
6
+ expect(tags.find((v) => v.approvalTagId == 235).approvalTagName).toEqual("Gandi 开发者");
7
+ });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.url = void 0;
7
+ exports.getApprovalTags = getApprovalTags;
8
+ const axios_1 = __importDefault(require("@ccw-api/axios"));
9
+ exports.url = "https://community-web.ccw.site/approval/list";
10
+ /**
11
+ * 获取特定用户的勋章数据
12
+ * @param {MongoDBId} studentOid 用户id
13
+ * @returns {Promise<Res<Tid, Tn>>} 勋章数据
14
+ */
15
+ async function getApprovalTags(studentOid) {
16
+ const req = {
17
+ objectId: studentOid,
18
+ objectType: "STUDENT",
19
+ };
20
+ return await axios_1.default
21
+ .post(exports.url, req)
22
+ .then((res) => res.data.body);
23
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.url = void 0;
7
+ exports.getTime = getTime;
8
+ const axios_1 = __importDefault(require("@ccw-api/axios"));
9
+ exports.url = "https://community-web.ccw.site/base/dateTime";
10
+ /**
11
+ * @returns {Promise<number>} 当前时间戳,相当于Date.now()
12
+ */
13
+ async function getTime() {
14
+ return axios_1.default
15
+ .post(exports.url, undefined)
16
+ .then((res) => res.data.body);
17
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dateTime_1 = require("../base/dateTime");
4
+ test("get time should return a number", async () => {
5
+ const time = await (0, dateTime_1.getTime)();
6
+ expect(typeof time).toBe("number");
7
+ expect(time).toBeGreaterThan(0);
8
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.url = void 0;
4
+ exports.getCampaignResources = getCampaignResources;
5
+ const axios_1 = require("@ccw-api/axios");
6
+ exports.url = "https://community-web.ccw.site/campaign_resource/detail";
7
+ /**
8
+ * 不知道这个接口有什么用,请查看https://www.ccw.site/pages/tags自行寻找用法
9
+ * @param {K} keyword 活动关键词
10
+ * @returns {Promise<Res<K>>}
11
+ */
12
+ async function getCampaignResources(keyword) {
13
+ return await axios_1.ccwAxios
14
+ .post(exports.url, { keyword })
15
+ .then((res) => res.data.body);
16
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const detail_1 = require("./detail");
4
+ test("get campaign resources with tags keyword", async () => {
5
+ const res = await (0, detail_1.getCampaignResources)("tags");
6
+ expect(res.keyword).toBe("tags");
7
+ expect(res.resourceType).toBe("SUBJECT_AREA");
8
+ });
9
+ test("get campaign resources with mmo keyword", async () => {
10
+ const res = await (0, detail_1.getCampaignResources)("mmo");
11
+ expect(res.keyword).toBe("mmo");
12
+ });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const detail_1 = require("./detail");
4
+ const insert_1 = require("./insert");
5
+ test("get check in records should fail without channel", async () => {
6
+ await expect(detail_1.getCheckInRecords).rejects.toThrow("ccw axios Request failed: token为空(4001082401)");
7
+ });
8
+ test("insert check in record should fail without token", async () => {
9
+ await expect(insert_1.insertCheckInRecord).rejects.toThrow("ccw axios Request failed: token为空(4001082401)");
10
+ });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.url = void 0;
4
+ exports.getCheckInRecords = getCheckInRecords;
5
+ const axios_1 = require("@ccw-api/axios");
6
+ exports.url = "https://community-web.ccw.site/check_in_record/detail";
7
+ async function getCheckInRecords() {
8
+ const req = { scene: "HOMEPAGE" };
9
+ return await axios_1.ccwAxios
10
+ .post(exports.url, req)
11
+ .then((res) => res.data.body);
12
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.url = void 0;
4
+ exports.insertCheckInRecord = insertCheckInRecord;
5
+ const axios_1 = require("@ccw-api/axios");
6
+ exports.url = "https://community-web.ccw.site/check_in_record/insert";
7
+ /**
8
+ * 插入签到记录
9
+ * @returns {Promise<boolean>} 是否成功
10
+ */
11
+ async function insertCheckInRecord() {
12
+ const req = { scene: "HOMEPAGE" };
13
+ return await axios_1.ccwAxios
14
+ .post(exports.url, req)
15
+ .then((res) => res.data.body);
16
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.url = void 0;
4
+ exports.searchCloudAssets = searchCloudAssets;
5
+ const axios_1 = require("@ccw-api/axios");
6
+ const queryPages_1 = require("src/queryPages");
7
+ exports.url = "https://community-web.ccw.site/cloud_asset/search";
8
+ const dpa = {
9
+ ...queryPages_1.DEFAULT_PAGE_ARGS,
10
+ sortField: "createdAt",
11
+ };
12
+ /**
13
+ *
14
+ * @param {MongoDBId} creatorOid 用户id
15
+ * @param {string} path 目录(例如'/23azZqHBnqj/2BzzTdi5I5C/')
16
+ * @param {Partial<PageArgs>} pageArgs_ 分页参数
17
+ * @returns {Promise<CloudAsset[]>} 目录内的素材
18
+ */
19
+ async function searchCloudAssets(creatorOid, path = "/", pageArgs_ = {}) {
20
+ const pageArgs = {
21
+ ...dpa,
22
+ ...pageArgs_,
23
+ };
24
+ const queryUrl = (0, queryPages_1.queryPage)(exports.url, pageArgs);
25
+ const req = { creatorOid, path };
26
+ return await axios_1.ccwAxios
27
+ .post(queryUrl, req)
28
+ .then((res) => res.data.body.data);
29
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const search_1 = require("./search");
4
+ test("search cloud assets should fail without token", async () => {
5
+ const userId = "63c2807d669fa967f17f5559";
6
+ const path = "/23azZqHBnqj/";
7
+ await expect((0, search_1.searchCloudAssets)(userId, path)).rejects.toThrow("ccw axios Request failed: token为空(4001082401)");
8
+ });
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.url = void 0;
4
+ exports.getUserAssetStorageSize = getUserAssetStorageSize;
5
+ const axios_1 = require("@ccw-api/axios");
6
+ exports.url = "https://community-web.ccw.site/cloud_asset/user/privacy";
7
+ /**
8
+ * 获取用户云存储空间信息
9
+ * @returns {Promise<Res>} 存储空间信息
10
+ */
11
+ async function getUserAssetStorageSize() {
12
+ return await axios_1.ccwAxios
13
+ .post(exports.url, {})
14
+ .then((res) => res.data.body);
15
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const privacy_1 = require("./privacy");
4
+ test("get user asset storage size should fail without token", async () => {
5
+ await expect((0, privacy_1.getUserAssetStorageSize)()).rejects.toThrow("ccw axios Request failed: token为空");
6
+ });