Skip to content

Commit

Permalink
chore: rivet module lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ABCxFF committed Sep 27, 2024
1 parent 45d6e7b commit 7b3a98d
Show file tree
Hide file tree
Showing 112 changed files with 1,668 additions and 1,453 deletions.
23 changes: 11 additions & 12 deletions modules/auth_email/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { schema, Query } from "./schema.gen.ts";
import { Query, schema } from "./schema.gen.ts";

export const verifications = schema.table('verifications', {
id: Query.uuid("id").primaryKey().defaultRandom(),
export const verifications = schema.table("verifications", {
id: Query.uuid("id").primaryKey().defaultRandom(),

email: Query.text("email").notNull(),
email: Query.text("email").notNull(),

code: Query.text("code").notNull().unique(),
token: Query.text("token").notNull().unique(),
code: Query.text("code").notNull().unique(),
token: Query.text("token").notNull().unique(),

attemptCount: Query.integer("attempt_count").notNull().default(0),
maxAttemptCount: Query.integer("max_attempt_count").notNull(),
attemptCount: Query.integer("attempt_count").notNull().default(0),
maxAttemptCount: Query.integer("max_attempt_count").notNull(),

createdAt: Query.timestamp("created_at").notNull().defaultNow(),
expireAt: Query.timestamp("expire_at").notNull(),
completedAt: Query.timestamp("completed_at"),
createdAt: Query.timestamp("created_at").notNull().defaultNow(),
expireAt: Query.timestamp("expire_at").notNull(),
completedAt: Query.timestamp("completed_at"),
});

9 changes: 5 additions & 4 deletions modules/auth_email/tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { TestContext, Query, Database } from "../module.gen.ts";
import { Database, Query, TestContext } from "../module.gen.ts";
import {
assertEquals,
assertExists,
} from "https://deno.land/std@0.208.0/assert/mod.ts";

export async function getVerification(ctx: TestContext, email: string) {
// Get a valid verification
const { verification: { token: verificationToken } } = await ctx.modules.authEmail
const { verification: { token: verificationToken } } = await ctx.modules
.authEmail
.sendVerification({ email });
const verification = await ctx.db.query.verifications.findFirst({
where: Query.eq(Database.verifications.token, verificationToken),
});
where: Query.eq(Database.verifications.token, verificationToken),
});
assertExists(verification);

return { verificationToken, code: verification.code };
Expand Down
17 changes: 13 additions & 4 deletions modules/auth_email/utils/code_management.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { RuntimeError, ScriptContext, Module, Database, Query } from "../module.gen.ts";
import {
Database,
Module,
Query,
RuntimeError,
ScriptContext,
} from "../module.gen.ts";

const MAX_ATTEMPT_COUNT = 3;
const EXPIRATION_TIME = 60 * 60 * 1000;

export async function createVerification(ctx: ScriptContext, email: string) {
// Create verification
const code = Module.tokens.generateRandomCodeSecure("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 8);
const code = Module.tokens.generateRandomCodeSecure(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
8,
);
const verification = await ctx.db.insert(Database.verifications)
.values({
token: Module.tokens.genSecureId(),
Expand Down Expand Up @@ -61,7 +70,7 @@ export async function verifyCode(
})
.where(Query.and(
Query.eq(Database.verifications.token, verificationToken),
Query.isNull(Database.verifications.completedAt)
Query.isNull(Database.verifications.completedAt),
))
.returning();
if (verificationConfirmation.length === 0) {
Expand All @@ -73,4 +82,4 @@ export async function verifyCode(
completedAt,
};
});
}
}
9 changes: 6 additions & 3 deletions modules/auth_email_link/scripts/send_verification.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["sendVerification"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["sendVerification"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["sendVerification"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["sendVerification"]
>;

export async function run(
ctx: ScriptContext,
Expand Down
10 changes: 6 additions & 4 deletions modules/auth_email_link/scripts/verify_link_email.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["verifyLinkEmail"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["verifyLinkEmail"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["verifyLinkEmail"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["verifyLinkEmail"]
>;

export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
return await ctx.modules.authEmail.verifyLinkEmail(req);
}

6 changes: 4 additions & 2 deletions modules/auth_email_link/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export type ReqOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Req : never;
export type ResOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Res : never;
export type ReqOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Req
: never;
export type ResOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Res
: never;
9 changes: 6 additions & 3 deletions modules/auth_email_password/scripts/send_verification.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["sendVerification"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["sendVerification"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["sendVerification"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["sendVerification"]
>;

export async function run(
ctx: ScriptContext,
Expand Down
10 changes: 6 additions & 4 deletions modules/auth_email_password/scripts/sign_in_email_pass.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["signInEmailPass"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["signInEmailPass"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["signInEmailPass"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["signInEmailPass"]
>;

export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
return await ctx.modules.authEmail.signInEmailPass(req);
}

9 changes: 6 additions & 3 deletions modules/auth_email_password/scripts/verify_add_email_pass.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["verifyAddEmailPass"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["verifyAddEmailPass"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["verifyAddEmailPass"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["verifyAddEmailPass"]
>;

export async function run(
ctx: ScriptContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["verifySignUpEmailPass"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["verifySignUpEmailPass"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["verifySignUpEmailPass"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["verifySignUpEmailPass"]
>;

export async function run(
ctx: ScriptContext,
Expand Down
6 changes: 4 additions & 2 deletions modules/auth_email_password/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export type ReqOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Req : never;
export type ResOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Res : never;
export type ReqOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Req
: never;
export type ResOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Res
: never;
9 changes: 6 additions & 3 deletions modules/auth_email_passwordless/scripts/send_verification.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["sendVerification"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["sendVerification"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["sendVerification"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["sendVerification"]
>;

export async function run(
ctx: ScriptContext,
Expand Down
9 changes: 6 additions & 3 deletions modules/auth_email_passwordless/scripts/verify_add_no_pass.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["verifyAddNoPass"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["verifyAddNoPass"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["verifyAddNoPass"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["verifyAddNoPass"]
>;

export async function run(
ctx: ScriptContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { RuntimeError, ScriptContext } from "../module.gen.ts";
import { ReqOf, ResOf } from "../utils/types.ts";


export type Request = ReqOf<ScriptContext["modules"]["authEmail"]["verifyLoginOrCreateNoPass"]>;
export type Response = ResOf<ScriptContext["modules"]["authEmail"]["verifyLoginOrCreateNoPass"]>;
export type Request = ReqOf<
ScriptContext["modules"]["authEmail"]["verifyLoginOrCreateNoPass"]
>;
export type Response = ResOf<
ScriptContext["modules"]["authEmail"]["verifyLoginOrCreateNoPass"]
>;

export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
return await ctx.modules.authEmail.verifyLoginOrCreateNoPass(req);
}

6 changes: 4 additions & 2 deletions modules/auth_email_passwordless/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export type ReqOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Req : never;
export type ResOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Res : never;
export type ReqOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Req
: never;
export type ResOf<T> = T extends (req: infer Req) => Promise<infer Res> ? Res
: never;
2 changes: 1 addition & 1 deletion modules/auth_username_password/scripts/sign_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export async function run(
}
}

return await ctx.modules.users.createToken({ userId: id });
return await ctx.modules.users.createToken({ userId: id });
}
8 changes: 5 additions & 3 deletions modules/auth_username_password/tests/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { test, TestContext } from "../module.gen.ts";
import { assertExists, assertEquals, assertRejects } from "https://deno.land/std@0.217.0/assert/mod.ts";
import {
assertEquals,
assertExists,
assertRejects,
} from "https://deno.land/std@0.217.0/assert/mod.ts";
import { faker } from "https://deno.land/x/deno_faker@v1.0.3/mod.ts";
import { RuntimeError } from "../module.gen.ts";

Expand All @@ -17,7 +21,6 @@ test("test_sign_up", async (ctx: TestContext) => {
userToken: token.token,
});


const { users: [user] } = await ctx.modules.users.fetchByUsername({
usernames: [username],
});
Expand Down Expand Up @@ -72,4 +75,3 @@ test("test_sign_in", async (ctx: TestContext) => {
}, RuntimeError);
assertEquals(error.code, "invalid_username_or_password");
});

16 changes: 8 additions & 8 deletions modules/captcha/actors/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export class Actor extends ActorBase<Input, State> {
return { success: false };
}

if (now - this.state.start > req.period) {
this.reset(_ctx, {});
return { success: true };
}
if (now - this.state.start > req.period) {
this.reset(_ctx, {});
return { success: true };
}

if (this.state.count > req.requests) {
return { success: false };
}
if (this.state.count > req.requests) {
return { success: false };
}

return { success: true };
return { success: true };
}

reset(_ctx: ActorContext, req: Empty): Empty {
Expand Down
Loading

0 comments on commit 7b3a98d

Please sign in to comment.