Skip to content

Commit bd8db17

Browse files
authored
Merge pull request #9 from listee-dev/add-workflow
Configure CI workflow and use published @Listee packages
2 parents 5133211 + 260bd0e commit bd8db17

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
lint:
10+
uses: listee-dev/listee-ci/.github/workflows/lint.yml@main
11+
12+
typecheck:
13+
uses: listee-dev/listee-ci/.github/workflows/typecheck.yml@main
14+
15+
test:
16+
uses: listee-dev/listee-ci/.github/workflows/test.yml@main

bun.lock

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"test": "bun test"
1515
},
1616
"dependencies": {
17-
"@listee/auth": "link:@listee/auth",
18-
"@listee/types": "link:@listee/types",
17+
"@listee/auth": "^0.2.3",
18+
"@listee/types": "^0.2.3",
1919
"@napi-rs/keyring": "^1.2.0",
2020
"commander": "^12.1.0",
2121
"dotenv": "^16.4.5"

src/commands/auth.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,19 @@ const startLoopbackServer = async (): Promise<LoopbackServer> => {
103103
let settled = false;
104104

105105
const server = createServer((req, res) => {
106-
const finish = (status: number, body: string, contentType = "text/html"): void => {
106+
const finish = (
107+
status: number,
108+
body: string,
109+
contentType = "text/html",
110+
): void => {
107111
res.writeHead(status, { "Content-Type": contentType });
108112
res.end(body);
109113
};
110114

111-
const respondWithJson = (status: number, payload: { title: string; message: string }): void => {
115+
const respondWithJson = (
116+
status: number,
117+
payload: { title: string; message: string },
118+
): void => {
112119
finish(status, JSON.stringify(payload), "application/json");
113120
};
114121

@@ -174,7 +181,11 @@ const startLoopbackServer = async (): Promise<LoopbackServer> => {
174181
});
175182

176183
const address = server.address();
177-
if (address === null || typeof address !== "object" || address.port === undefined) {
184+
if (
185+
address === null ||
186+
typeof address !== "object" ||
187+
address.port === undefined
188+
) {
178189
server.close();
179190
throw new Error("Failed to determine loopback server port.");
180191
}
@@ -200,7 +211,8 @@ const startLoopbackServer = async (): Promise<LoopbackServer> => {
200211

201212
return {
202213
redirectUrl: `http://${LOOPBACK_HOST}:${address.port}/callback`,
203-
waitForConfirmation: () => waitForConfirmation.finally(() => clearTimeout(timeout)),
214+
waitForConfirmation: () =>
215+
waitForConfirmation.finally(() => clearTimeout(timeout)),
204216
shutdown,
205217
};
206218
};
@@ -344,7 +356,9 @@ const signupAction = async (options: EmailOption): Promise<void> => {
344356

345357
try {
346358
await signup(email, password, loopback.redirectUrl);
347-
console.log("📩 Confirmation email sent. Keep this terminal open while you click the link.");
359+
console.log(
360+
"📩 Confirmation email sent. Keep this terminal open while you click the link.",
361+
);
348362
const result = await loopback.waitForConfirmation();
349363
console.log(`✅ Signup confirmed for ${result.account}.`);
350364
} finally {

src/services/auth-service.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,20 @@ describe("parseSignupFragment", () => {
6767
};
6868

6969
const header = encodeSegment(JSON.stringify({ alg: "HS256", typ: "JWT" }));
70-
const payload = encodeSegment(JSON.stringify({ email: "user@example.com" }));
70+
const payloadSegment = (): string => {
71+
const currentEpoch = Math.floor(Date.now() / 1000);
72+
const payload = {
73+
sub: "user-id",
74+
email: "user@example.com",
75+
exp: currentEpoch + 3600,
76+
iat: currentEpoch,
77+
};
78+
return encodeSegment(JSON.stringify(payload));
79+
};
7180
const signature = encodeSegment("signature");
72-
const accessToken = `${header}.${payload}.${signature}`;
7381

7482
it("parses tokens from a confirmation fragment", () => {
83+
const accessToken = `${header}.${payloadSegment()}.${signature}`;
7584
const fragment = `#access_token=${accessToken}&refresh_token=refresh123&expires_in=3600&token_type=bearer&type=signup`;
7685
const result = parseSignupFragment(fragment);
7786

0 commit comments

Comments
 (0)