@ccw-api/api 0.0.1 → 0.1.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/dist/esm/index.js +2 -2
- package/dist/esm/sso/index.js +3 -3
- package/dist/esm/sso/web/auth/auth.test.js +61 -9
- package/dist/esm/sso/web/auth/login-by-password.js +82 -17
- package/dist/esm/sso/web/auth/logout.js +48 -5
- package/dist/node/index.js +3 -3
- package/dist/node/sso/index.js +2 -2
- package/dist/node/sso/web/auth/auth.test.js +63 -11
- package/dist/node/sso/web/auth/login-by-password.js +82 -17
- package/dist/node/sso/web/auth/logout.js +48 -5
- package/dist/{esm → types}/index.d.ts +1 -1
- package/package.json +16 -7
- package/src/index.ts +1 -1
- package/tsconfig.esm.json +2 -1
- package/tsconfig.json +4 -2
- package/tsconfig.node.json +3 -1
- package/tsconfig.types.json +9 -0
- package/dist/esm/sso/web/auth/auth.test.d.ts +0 -1
- package/dist/node/index.d.ts +0 -10
- package/dist/node/sso/index.d.ts +0 -6
- package/dist/node/sso/web/auth/auth.test.d.ts +0 -1
- package/dist/node/sso/web/auth/login-by-password.d.ts +0 -38
- package/dist/node/sso/web/auth/logout.d.ts +0 -3
- package/dist/node/types.d.ts +0 -17
- /package/dist/{esm → types}/sso/index.d.ts +0 -0
- /package/dist/{esm → types}/sso/web/auth/login-by-password.d.ts +0 -0
- /package/dist/{esm → types}/sso/web/auth/logout.d.ts +0 -0
- /package/dist/{esm → types}/types.d.ts +0 -0
package/dist/esm/index.js
CHANGED
package/dist/esm/sso/index.js
CHANGED
|
@@ -1,11 +1,63 @@
|
|
|
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
|
+
};
|
|
1
37
|
import { loginByPassword } from "./login-by-password";
|
|
2
38
|
import { logout } from "./logout";
|
|
3
|
-
test("expect password to be error",
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
test
|
|
10
|
-
|
|
11
|
-
});
|
|
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
|
+
}); });
|
|
@@ -1,19 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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),
|
|
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;
|
|
18
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
|
+
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
|
+
});
|
|
19
84
|
}
|
|
@@ -1,7 +1,50 @@
|
|
|
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
|
+
};
|
|
1
37
|
import { ccwAxios } from "@ccw-api/axios";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
});
|
|
7
50
|
}
|
package/dist/node/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sso = void 0;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "sso", { enumerable: true, get: function () { return
|
|
4
|
+
var index_1 = require("./sso/index");
|
|
5
|
+
Object.defineProperty(exports, "sso", { enumerable: true, get: function () { return index_1.sso; } });
|
|
6
6
|
exports.default = {
|
|
7
|
-
sso:
|
|
7
|
+
sso: index_1.sso,
|
|
8
8
|
};
|
package/dist/node/sso/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sso = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var login_by_password_1 = require("./web/auth/login-by-password");
|
|
5
|
+
var logout_1 = require("./web/auth/logout");
|
|
6
6
|
exports.sso = {
|
|
7
7
|
loginByPassword: login_by_password_1.loginByPassword,
|
|
8
8
|
logout: logout_1.logout,
|
|
@@ -1,13 +1,65 @@
|
|
|
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
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
test("expect password to be error",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
test
|
|
12
|
-
|
|
13
|
-
});
|
|
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
|
+
}); });
|
|
@@ -1,23 +1,88 @@
|
|
|
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
|
+
};
|
|
2
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
61
|
exports.url = void 0;
|
|
4
62
|
exports.loginByPassword = loginByPassword;
|
|
5
|
-
|
|
63
|
+
var axios_1 = require("@ccw-api/axios");
|
|
6
64
|
exports.url = "https://sso.ccw.site/web/auth/login-by-password";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
});
|
|
23
88
|
}
|
|
@@ -1,11 +1,54 @@
|
|
|
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
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.url = void 0;
|
|
4
40
|
exports.logout = logout;
|
|
5
|
-
|
|
41
|
+
var axios_1 = require("@ccw-api/axios");
|
|
6
42
|
exports.url = "https://sso.ccw.site/web/auth/logout";
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
});
|
|
11
54
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ccw-api/api",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "ccw api collections",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Meng Fuzi",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "dist/node/index.
|
|
9
|
-
"module": "dist/esm/index.
|
|
8
|
+
"main": "dist/node/index.js",
|
|
9
|
+
"module": "dist/esm/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/node/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
10
18
|
"scripts": {
|
|
11
|
-
"prepublishOnly": "npm run build
|
|
19
|
+
"prepublishOnly": "npm run build && npm test",
|
|
12
20
|
"test": "jest",
|
|
13
|
-
"build": "tsc --project tsconfig.node.json
|
|
21
|
+
"build": "tsc --project tsconfig.node.json && tsc --project tsconfig.esm.json && tsc --project tsconfig.types.json"
|
|
14
22
|
},
|
|
15
23
|
"dependencies": {
|
|
16
|
-
"@ccw-api/axios": "^
|
|
24
|
+
"@ccw-api/axios": "^2.1.0"
|
|
17
25
|
},
|
|
18
26
|
"devDependencies": {
|
|
19
27
|
"@types/jest": "^30.0.0",
|
|
28
|
+
"@types/node": "^26.0.1",
|
|
20
29
|
"jest": "^30.4.2",
|
|
21
|
-
"ts-jest": "^29.
|
|
30
|
+
"ts-jest": "^29.1.2"
|
|
22
31
|
}
|
|
23
32
|
}
|
package/src/index.ts
CHANGED
package/tsconfig.esm.json
CHANGED
package/tsconfig.json
CHANGED
package/tsconfig.node.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/node/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
package/dist/node/sso/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -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/node/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
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|