daystar-verify 1.0.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/.github/workflows/publish.yml +27 -0
- package/README.md +75 -0
- package/dist/auth.d.ts +15 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +50 -0
- package/dist/auth.js.map +1 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +10 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/package.json +24 -0
- package/src/auth.ts +52 -0
- package/src/config.ts +6 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: 20
|
|
17
|
+
registry-url: "https://registry.npmjs.org"
|
|
18
|
+
|
|
19
|
+
- uses: pnpm/action-setup@v3
|
|
20
|
+
with:
|
|
21
|
+
version: 10
|
|
22
|
+
|
|
23
|
+
- run: pnpm install
|
|
24
|
+
- run: pnpm run build
|
|
25
|
+
- run: npm publish
|
|
26
|
+
env:
|
|
27
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# daystar-verify
|
|
2
|
+
|
|
3
|
+
Verify that a student exists at Daystar University by authenticating against the student portal.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install daystar-verify
|
|
9
|
+
# or
|
|
10
|
+
pnpm add daystar-verify
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Environment Variable
|
|
14
|
+
|
|
15
|
+
Set the Daystar portal URL in your environment:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
DAYSTAR_PORTAL_URL=https://your-portal-url.com
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { fetchSessionToken, login } from "daystar-verify";
|
|
25
|
+
|
|
26
|
+
async function verifyStudent(admno: string, password: string) {
|
|
27
|
+
const token = await fetchSessionToken();
|
|
28
|
+
const session = await login(token, admno, password);
|
|
29
|
+
return session;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Error Handling
|
|
34
|
+
|
|
35
|
+
Both functions throw on failure, so wrap in a try/catch:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { fetchSessionToken, login } from "daystar-verify";
|
|
39
|
+
|
|
40
|
+
async function verifyStudent(admno: string, password: string) {
|
|
41
|
+
try {
|
|
42
|
+
const token = await fetchSessionToken();
|
|
43
|
+
const session = await login(token, admno, password);
|
|
44
|
+
return session;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.error("Verification failed:", err.message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Common errors:
|
|
52
|
+
|
|
53
|
+
- `Failed to communicate with server` — portal is unreachable
|
|
54
|
+
- `Failed to retrieve session token` — unexpected response from portal
|
|
55
|
+
- `Unauthorised Login. Visit Registrar's Office` — invalid credentials
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
### `fetchSessionToken(): Promise<string>`
|
|
60
|
+
|
|
61
|
+
Hits the portal root and retrieves an initial session cookie required for login.
|
|
62
|
+
|
|
63
|
+
### `login(sessionId, admno, password): Promise<string>`
|
|
64
|
+
|
|
65
|
+
Authenticates the student and returns a session string on success.
|
|
66
|
+
|
|
67
|
+
| Parameter | Type | Description |
|
|
68
|
+
|-------------|----------|------------------------------------------|
|
|
69
|
+
| `sessionId` | `string` | Token returned by `fetchSessionToken()` |
|
|
70
|
+
| `admno` | `string` | Student admission number |
|
|
71
|
+
| `password` | `string` | Student password |
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
ISC
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a session token from the server.
|
|
3
|
+
* @returns The session token as a string.
|
|
4
|
+
* @throws If the request fails or the token cannot be retrieved.
|
|
5
|
+
*/
|
|
6
|
+
export declare function fetchSessionToken(): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Logs in a user and returns the session cookie.
|
|
9
|
+
* @param sessionId
|
|
10
|
+
* @param admno
|
|
11
|
+
* @param password
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function login(sessionId: string, admno: string, password: string): Promise<string>;
|
|
15
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CASzD;AAED;;;;;;GAMG;AACH,wBAAsB,KAAK,CACzB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAsBjB"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchSessionToken = fetchSessionToken;
|
|
4
|
+
exports.login = login;
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a session token from the server.
|
|
8
|
+
* @returns The session token as a string.
|
|
9
|
+
* @throws If the request fails or the token cannot be retrieved.
|
|
10
|
+
*/
|
|
11
|
+
async function fetchSessionToken() {
|
|
12
|
+
const res = await fetch(`${config_1.config.baseUrl}/`);
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
throw new Error("Failed to communicate with server");
|
|
15
|
+
const cookie = res.headers.get("set-cookie") ?? "";
|
|
16
|
+
const token = cookie.split(" ")[0];
|
|
17
|
+
if (!token)
|
|
18
|
+
throw new Error("Failed to retrieve session token");
|
|
19
|
+
return token;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Logs in a user and returns the session cookie.
|
|
23
|
+
* @param sessionId
|
|
24
|
+
* @param admno
|
|
25
|
+
* @param password
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
async function login(sessionId, admno, password) {
|
|
29
|
+
if (!sessionId)
|
|
30
|
+
throw new Error("sessionId is empty");
|
|
31
|
+
const res = await fetch(`${config_1.config.baseUrl}/Login/LoginUser`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
Cookie: sessionId,
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({ Username: admno, Password: password }),
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok)
|
|
40
|
+
throw new Error(`Request failed with status ${res.status}`);
|
|
41
|
+
const body = await res.json();
|
|
42
|
+
if (!body.success)
|
|
43
|
+
throw new Error(body.message ?? "Login failed");
|
|
44
|
+
const newCookie = res.headers.get("set-cookie") ?? "";
|
|
45
|
+
const userSession = `${sessionId} ${newCookie}`.trim();
|
|
46
|
+
if (!userSession)
|
|
47
|
+
throw new Error("Failed to retrieve user session");
|
|
48
|
+
return userSession;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADD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,GAAG,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,cAAc,CAAC,CAAC;IAEnE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACtD,MAAM,WAAW,GAAG,GAAG,SAAS,IAAI,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC;IACvD,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAErE,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,MAAM;;CAElB,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.config = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the Daystar Verify package.
|
|
6
|
+
*/
|
|
7
|
+
exports.config = {
|
|
8
|
+
baseUrl: process.env.DAYSTAR_PORTAL_URL ?? "",
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE;CAC9C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.config = exports.login = exports.fetchSessionToken = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
Object.defineProperty(exports, "fetchSessionToken", { enumerable: true, get: function () { return auth_1.fetchSessionToken; } });
|
|
6
|
+
Object.defineProperty(exports, "login", { enumerable: true, get: function () { return auth_1.login; } });
|
|
7
|
+
const config_1 = require("./config");
|
|
8
|
+
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAkD;AAGzC,kGAHA,wBAAiB,OAGA;AAAE,sFAHA,YAAK,OAGA;AAFjC,qCAAkC;AAEC,uFAF1B,eAAM,OAE0B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "daystar-verify",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"daystar",
|
|
12
|
+
"student",
|
|
13
|
+
"verify"
|
|
14
|
+
],
|
|
15
|
+
"author": "victor musembi",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"packageManager": "pnpm@10.18.2",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.5.2",
|
|
20
|
+
"dotenv": "^17.4.1",
|
|
21
|
+
"tsx": "^4.21.0",
|
|
22
|
+
"typescript": "^6.0.2"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/auth.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { config } from "./config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetches a session token from the server.
|
|
5
|
+
* @returns The session token as a string.
|
|
6
|
+
* @throws If the request fails or the token cannot be retrieved.
|
|
7
|
+
*/
|
|
8
|
+
export async function fetchSessionToken(): Promise<string> {
|
|
9
|
+
const res = await fetch(`${config.baseUrl}/`);
|
|
10
|
+
if (!res.ok) throw new Error("Failed to communicate with server");
|
|
11
|
+
|
|
12
|
+
const cookie = res.headers.get("set-cookie") ?? "";
|
|
13
|
+
const token = cookie.split(" ")[0];
|
|
14
|
+
if (!token) throw new Error("Failed to retrieve session token");
|
|
15
|
+
|
|
16
|
+
return token;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Logs in a user and returns the session cookie.
|
|
21
|
+
* @param sessionId
|
|
22
|
+
* @param admno
|
|
23
|
+
* @param password
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export async function login(
|
|
27
|
+
sessionId: string,
|
|
28
|
+
admno: string,
|
|
29
|
+
password: string,
|
|
30
|
+
): Promise<string> {
|
|
31
|
+
if (!sessionId) throw new Error("sessionId is empty");
|
|
32
|
+
|
|
33
|
+
const res = await fetch(`${config.baseUrl}/Login/LoginUser`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Cookie: sessionId,
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({ Username: admno, Password: password }),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!res.ok) throw new Error(`Request failed with status ${res.status}`);
|
|
43
|
+
|
|
44
|
+
const body = await res.json();
|
|
45
|
+
if (!body.success) throw new Error(body.message ?? "Login failed");
|
|
46
|
+
|
|
47
|
+
const newCookie = res.headers.get("set-cookie") ?? "";
|
|
48
|
+
const userSession = `${sessionId} ${newCookie}`.trim();
|
|
49
|
+
if (!userSession) throw new Error("Failed to retrieve user session");
|
|
50
|
+
|
|
51
|
+
return userSession;
|
|
52
|
+
}
|
package/src/config.ts
ADDED
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "./src",
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node10",
|
|
7
|
+
"ignoreDeprecations": "6.0",
|
|
8
|
+
"target": "esnext",
|
|
9
|
+
"types": [
|
|
10
|
+
"node"
|
|
11
|
+
],
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"noUncheckedIndexedAccess": true,
|
|
16
|
+
"exactOptionalPropertyTypes": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"moduleDetection": "force",
|
|
20
|
+
"skipLibCheck": true
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src"
|
|
24
|
+
]
|
|
25
|
+
}
|