@ccw-api/api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/sso/index.d.ts +6 -0
- package/dist/esm/sso/index.js +6 -0
- package/dist/esm/sso/web/auth/auth.test.d.ts +1 -0
- package/dist/esm/sso/web/auth/auth.test.js +11 -0
- package/dist/esm/sso/web/auth/login-by-password.d.ts +38 -0
- package/dist/esm/sso/web/auth/login-by-password.js +19 -0
- package/dist/esm/sso/web/auth/logout.d.ts +3 -0
- package/dist/esm/sso/web/auth/logout.js +7 -0
- package/dist/esm/types.d.ts +17 -0
- package/dist/esm/types.js +1 -0
- package/dist/node/index.d.ts +10 -0
- package/dist/node/index.js +8 -0
- package/dist/node/sso/index.d.ts +6 -0
- package/dist/node/sso/index.js +9 -0
- package/dist/node/sso/web/auth/auth.test.d.ts +1 -0
- package/dist/node/sso/web/auth/auth.test.js +13 -0
- package/dist/node/sso/web/auth/login-by-password.d.ts +38 -0
- package/dist/node/sso/web/auth/login-by-password.js +23 -0
- package/dist/node/sso/web/auth/logout.d.ts +3 -0
- package/dist/node/sso/web/auth/logout.js +11 -0
- package/dist/node/types.d.ts +17 -0
- package/dist/node/types.js +2 -0
- package/jest.config.ts +13 -0
- package/package.json +23 -0
- package/src/index.ts +8 -0
- package/src/sso/index.ts +7 -0
- package/src/sso/web/auth/auth.test.ts +16 -0
- package/src/sso/web/auth/login-by-password.ts +58 -0
- package/src/sso/web/auth/logout.ts +9 -0
- package/src/types.ts +18 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +10 -0
- package/tsconfig.node.json +7 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { sso } from "./sso";
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { loginByPassword } from "./login-by-password";
|
|
2
|
+
import { logout } from "./logout";
|
|
3
|
+
test("expect password to be error", async () => {
|
|
4
|
+
await expect(() => loginByPassword("abc", "foo", {
|
|
5
|
+
device: "test",
|
|
6
|
+
browser: "test",
|
|
7
|
+
})).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)");
|
|
8
|
+
});
|
|
9
|
+
test("expect logout to be error when no token", async () => {
|
|
10
|
+
await expect(logout).rejects.toThrow("ccw axios Request failed: token不能为空(4001092X01)");
|
|
11
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ccwAxios } from "@ccw-api/axios";
|
|
2
|
+
export const url = "https://sso.ccw.site/web/auth/login-by-password";
|
|
3
|
+
export async function loginByPassword(loginKey, password, reqExtra = {
|
|
4
|
+
device: "Node",
|
|
5
|
+
browser: "Node.js",
|
|
6
|
+
}) {
|
|
7
|
+
const { extra: _extra, ...rest } = await ccwAxios
|
|
8
|
+
.post(url, {
|
|
9
|
+
loginKey,
|
|
10
|
+
password,
|
|
11
|
+
clientCode: "STUDY_COMMUNITY",
|
|
12
|
+
extra: JSON.stringify({ ...reqExtra, scene: null }),
|
|
13
|
+
})
|
|
14
|
+
.then((res) => res.data.body);
|
|
15
|
+
return {
|
|
16
|
+
...rest,
|
|
17
|
+
extra: JSON.parse(_extra),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { sso } from "./sso";
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sso = void 0;
|
|
4
|
+
const sso_1 = require("./sso");
|
|
5
|
+
Object.defineProperty(exports, "sso", { enumerable: true, get: function () { return sso_1.sso; } });
|
|
6
|
+
exports.default = {
|
|
7
|
+
sso: sso_1.sso,
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sso = void 0;
|
|
4
|
+
const login_by_password_1 = require("./web/auth/login-by-password");
|
|
5
|
+
const logout_1 = require("./web/auth/logout");
|
|
6
|
+
exports.sso = {
|
|
7
|
+
loginByPassword: login_by_password_1.loginByPassword,
|
|
8
|
+
logout: logout_1.logout,
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const login_by_password_1 = require("./login-by-password");
|
|
4
|
+
const logout_1 = require("./logout");
|
|
5
|
+
test("expect password to be error", async () => {
|
|
6
|
+
await expect(() => (0, login_by_password_1.loginByPassword)("abc", "foo", {
|
|
7
|
+
device: "test",
|
|
8
|
+
browser: "test",
|
|
9
|
+
})).rejects.toThrow("ccw axios Request failed: 账号或密码错误(4001092401)");
|
|
10
|
+
});
|
|
11
|
+
test("expect logout to be error when no token", async () => {
|
|
12
|
+
await expect(logout_1.logout).rejects.toThrow("ccw axios Request failed: token不能为空(4001092X01)");
|
|
13
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.url = void 0;
|
|
4
|
+
exports.loginByPassword = loginByPassword;
|
|
5
|
+
const axios_1 = require("@ccw-api/axios");
|
|
6
|
+
exports.url = "https://sso.ccw.site/web/auth/login-by-password";
|
|
7
|
+
async function loginByPassword(loginKey, password, reqExtra = {
|
|
8
|
+
device: "Node",
|
|
9
|
+
browser: "Node.js",
|
|
10
|
+
}) {
|
|
11
|
+
const { extra: _extra, ...rest } = await axios_1.ccwAxios
|
|
12
|
+
.post(exports.url, {
|
|
13
|
+
loginKey,
|
|
14
|
+
password,
|
|
15
|
+
clientCode: "STUDY_COMMUNITY",
|
|
16
|
+
extra: JSON.stringify({ ...reqExtra, scene: null }),
|
|
17
|
+
})
|
|
18
|
+
.then((res) => res.data.body);
|
|
19
|
+
return {
|
|
20
|
+
...rest,
|
|
21
|
+
extra: JSON.parse(_extra),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.url = void 0;
|
|
4
|
+
exports.logout = logout;
|
|
5
|
+
const axios_1 = require("@ccw-api/axios");
|
|
6
|
+
exports.url = "https://sso.ccw.site/web/auth/logout";
|
|
7
|
+
async function logout() {
|
|
8
|
+
return await axios_1.ccwAxios
|
|
9
|
+
.post(exports.url, {})
|
|
10
|
+
.then((res) => res.data);
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ccw-api/api",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "ccw api collections",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Meng Fuzi",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/node/index.ts",
|
|
9
|
+
"module": "dist/esm/index.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prepublishOnly": "npm run build & npm test",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"build": "tsc --project tsconfig.node.json & tsc --project tsconfig.esm.json"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@ccw-api/axios": "^1.2.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/jest": "^30.0.0",
|
|
20
|
+
"jest": "^30.4.2",
|
|
21
|
+
"ts-jest": "^29.4.11"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
package/src/sso/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
};
|
package/tsconfig.json
ADDED