Skip to content

Commit

Permalink
Fix block cli and indexes (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso authored Nov 11, 2024
1 parent a720352 commit a24254e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/commands/addBlockRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default (
await tasks.clientTaskManager.addUserBlockRules(
argv.users as unknown as string[],
argv.hardBlock as boolean,
argv.global as boolean,
argv.dapp as unknown as string,
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/provider/src/tasks/client/clientTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ export class ClientTaskManager {
async addUserBlockRules(
userAccounts: string[],
hardBlock: boolean,
dappAccount: string,
global: boolean,
dappAccount?: string,
): Promise<void> {
validateAddress(dappAccount, false, 42);
const rules: UserAccountBlockRule[] = userAccounts.map((userAccount) => {
Expand All @@ -242,8 +243,7 @@ export class ClientTaskManager {
dappAccount,
userAccount,
type: BlockRuleType.userAccount,
// TODO don't store global on these
global: false,
global,
hardBlock,
};
});
Expand Down
24 changes: 16 additions & 8 deletions packages/types-database/src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ export type IUserDataSlim = Pick<IUserData, "account" | "settings">;

export type ClientRecord = IUserDataSlim & Document;

const ONE_WEEK = 60 * 60 * 24 * 7;
const ONE_DAY = 60 * 60 * 24;
const ONE_WEEK = ONE_DAY * 7;
const ONE_MONTH = ONE_WEEK * 4;

export const ClientRecordSchema = new Schema<ClientRecord>({
account: String,
settings: UserSettingsSchema,
});
// Set an index on the account field, ascending
ClientRecordSchema.index({ account: 1 });

export enum StoredStatusNames {
notStored = "notStored",
Expand Down Expand Up @@ -193,7 +196,7 @@ export const PoWCaptchaRecordSchema = new Schema<PoWCaptchaRecord>(
);

// Set an index on the captchaId field, ascending
PoWCaptchaRecordSchema.index({ captchaId: 1 });
PoWCaptchaRecordSchema.index({ challenge: 1 });

export const UserCommitmentRecordSchema = new Schema<UserCommitmentRecord>({
userAccount: { type: String, required: true },
Expand Down Expand Up @@ -331,10 +334,13 @@ export type Session = {

export type SessionRecord = mongoose.Document & Session;

export const SessionRecordSchema = new Schema<SessionRecord>({
sessionId: { type: String, required: true, unique: true },
createdAt: { type: Date, required: true },
});
export const SessionRecordSchema = new Schema<SessionRecord>(
{
sessionId: { type: String, required: true, unique: true },
createdAt: { type: Date, required: true },
},
{ expireAfterSeconds: ONE_DAY },
);

type BlockRule = {
global: boolean;
Expand All @@ -353,7 +359,7 @@ export interface IPAddressBlockRule extends BlockRule {
}

export interface UserAccountBlockRule extends BlockRule {
dappAccount: string;
dappAccount?: string;
userAccount: string;
}

Expand All @@ -375,16 +381,18 @@ export const IPBlockRuleRecordSchema = new Schema<IPBlockRuleRecord>({
});

IPBlockRuleRecordSchema.index({ ip: 1 }, { unique: true });
IPBlockRuleRecordSchema.index({ ip: 1, dappAccount: 1 }, { unique: true });

export const UserAccountBlockRuleSchema =
new Schema<UserAccountBlockRuleRecord>({
dappAccount: { type: String, required: true },
dappAccount: { type: String, required: false },
userAccount: { type: String, required: true },
global: { type: Boolean, required: true },
hardBlock: { type: Boolean, required: false },
type: { type: String, enum: BlockRuleType, required: true },
});

UserAccountBlockRuleSchema.index({ userAccount: 1 }, { unique: true });
UserAccountBlockRuleSchema.index(
{ dappAccount: 1, userAccount: 1 },
{ unique: true },
Expand Down

0 comments on commit a24254e

Please sign in to comment.