Skip to content

Commit

Permalink
Merge branch 'master' into fix/router
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx authored and rubyowo committed Jun 2, 2024
2 parents 7252aa1 + c24a246 commit 2c6b176
Show file tree
Hide file tree
Showing 773 changed files with 3,822 additions and 5,026 deletions.
9 changes: 2 additions & 7 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"description": "",
"private": true,
"type": "module",
"scripts": {
"watch": "tsc-watch --build --onSuccess \"node start-dev.js\"",
"watch-yaml-parse-test": "tsc-watch --build --onSuccess \"node dist/yamlParseTest.js\"",
Expand Down Expand Up @@ -48,12 +49,7 @@
"knub": "^32.0.0-next.21",
"knub-command-manager": "^9.1.0",
"last-commit-log": "^2.1.0",
"lodash.chunk": "^4.2.0",
"lodash.clonedeep": "^4.5.0",
"lodash.difference": "^4.5.0",
"lodash.intersection": "^4.4.0",
"lodash.isequal": "^4.5.0",
"lodash.pick": "^4.4.0",
"lodash": "^4.17.21",
"moment-timezone": "^0.5.21",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.9.3",
Expand Down Expand Up @@ -87,7 +83,6 @@
"@types/lodash.at": "^4.6.3",
"@types/moment-timezone": "^0.5.6",
"@types/multer": "^1.4.7",
"@types/node": "^18.16.3",
"@types/passport": "^1.0.0",
"@types/passport-oauth2": "^1.4.8",
"@types/passport-strategy": "^0.2.35",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/Queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SECONDS } from "./utils";
import { SECONDS } from "./utils.js";

type InternalQueueFn = () => Promise<void>;
type AnyFn = (...args: any[]) => any;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/QueuedEventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue } from "./Queue";
import { Queue } from "./Queue.js";

type Listener = (...args: any[]) => void;

Expand Down
2 changes: 1 addition & 1 deletion backend/src/RegExpRunner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from "events";
import { CooldownManager } from "knub";
import { RegExpWorker, TimeoutError } from "regexp-worker";
import { MINUTES, SECONDS } from "./utils";
import { MINUTES, SECONDS } from "./utils.js";
import Timeout = NodeJS.Timeout;

const isTimeoutError = (a): a is TimeoutError => {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/api/archives.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express, { Request, Response } from "express";
import moment from "moment-timezone";
import { GuildArchives } from "../data/GuildArchives";
import { notFound } from "./responses";
import { GuildArchives } from "../data/GuildArchives.js";
import { notFound } from "./responses.js";

export function initArchives(router: express.Router) {
const archives = new GuildArchives(null);
Expand Down
14 changes: 7 additions & 7 deletions backend/src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import express, { Request, Response } from "express";
import https from "https";
import pick from "lodash.pick";
import pick from "lodash/pick.js";
import passport from "passport";
import { Strategy as CustomStrategy } from "passport-custom";
import OAuth2Strategy from "passport-oauth2";
import { ApiLogins } from "../data/ApiLogins";
import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments";
import { ApiUserInfo } from "../data/ApiUserInfo";
import { ApiUserInfoData } from "../data/entities/ApiUserInfo";
import { env } from "../env";
import { ok } from "./responses";
import { ApiLogins } from "../data/ApiLogins.js";
import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments.js";
import { ApiUserInfo } from "../data/ApiUserInfo.js";
import { ApiUserInfoData } from "../data/entities/ApiUserInfo.js";
import { env } from "../env.js";
import { ok } from "./responses.js";

interface IPassportApiUser {
apiKey: string;
Expand Down
15 changes: 7 additions & 8 deletions backend/src/api/docs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express from "express";
import z from "zod";
import { guildPlugins } from "../plugins/availablePlugins";
import { guildPluginInfo } from "../plugins/pluginInfo";
import { indentLines } from "../utils";
import { notFound } from "./responses";
import { guildPlugins } from "../plugins/availablePlugins.js";
import { guildPluginInfo } from "../plugins/pluginInfo.js";
import { indentLines } from "../utils.js";
import { notFound } from "./responses.js";

function isZodObject(schema: z.ZodTypeAny): schema is z.ZodObject<any> {
return schema._def.typeName === "ZodObject";
Expand Down Expand Up @@ -121,8 +121,8 @@ export function initDocs(router: express.Router) {
}

const plugin = guildPlugins.find((p) => p.name === name)!;
const info = { ...baseInfo };
delete info.configSchema;
const { configSchema, ...info } = baseInfo;
const formattedConfigSchema = formatZodConfigSchema(configSchema);

const messageCommands = (plugin.messageCommands || []).map((cmd) => ({
trigger: cmd.trigger,
Expand All @@ -134,12 +134,11 @@ export function initDocs(router: express.Router) {
}));

const defaultOptions = plugin.defaultOptions || {};
const configSchema = info.configSchema && formatZodConfigSchema(info.configSchema);

res.json({
name,
info,
configSchema,
configSchema: formattedConfigSchema,
defaultOptions,
messageCommands,
});
Expand Down
32 changes: 17 additions & 15 deletions backend/src/api/guilds.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { ApiPermissions } from "@zeppelinbot/shared";
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import express, { Request, Response } from "express";
import { YAMLException } from "js-yaml";
import jsYaml from "js-yaml";
import moment from "moment-timezone";
import { Queue } from "../Queue";
import { validateGuildConfig } from "../configValidator";
import { AllowedGuilds } from "../data/AllowedGuilds";
import { ApiAuditLog } from "../data/ApiAuditLog";
import { ApiPermissionAssignments, ApiPermissionTypes } from "../data/ApiPermissionAssignments";
import { Configs } from "../data/Configs";
import { AuditLogEventTypes } from "../data/apiAuditLogTypes";
import { isSnowflake } from "../utils";
import { loadYamlSafely } from "../utils/loadYamlSafely";
import { ObjectAliasError } from "../utils/validateNoObjectAliases";
import { apiTokenAuthHandlers } from "./auth";
import { hasGuildPermission, requireGuildPermission } from "./permissions";
import { clientError, ok, serverError, unauthorized } from "./responses";
import { Queue } from "../Queue.js";
import { validateGuildConfig } from "../configValidator.js";
import { AllowedGuilds } from "../data/AllowedGuilds.js";
import { ApiAuditLog } from "../data/ApiAuditLog.js";
import { ApiPermissionAssignments, ApiPermissionTypes } from "../data/ApiPermissionAssignments.js";
import { Configs } from "../data/Configs.js";
import { AuditLogEventTypes } from "../data/apiAuditLogTypes.js";
import { isSnowflake } from "../utils.js";
import { loadYamlSafely } from "../utils/loadYamlSafely.js";
import { ObjectAliasError } from "../utils/validateNoObjectAliases.js";
import { apiTokenAuthHandlers } from "./auth.js";
import { hasGuildPermission, requireGuildPermission } from "./permissions.js";
import { clientError, ok, serverError, unauthorized } from "./responses.js";

const YAMLException = jsYaml.YAMLException;

const apiPermissionAssignments = new ApiPermissionAssignments();
const auditLog = new ApiAuditLog();
Expand Down
14 changes: 7 additions & 7 deletions backend/src/api/guilds/importExport.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApiPermissions } from "@zeppelinbot/shared";
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import express, { Request, Response } from "express";
import moment from "moment-timezone";
import { z } from "zod";
import { GuildCases } from "../../data/GuildCases";
import { Case } from "../../data/entities/Case";
import { MINUTES } from "../../utils";
import { requireGuildPermission } from "../permissions";
import { rateLimit } from "../rateLimits";
import { clientError, ok } from "../responses";
import { GuildCases } from "../../data/GuildCases.js";
import { Case } from "../../data/entities/Case.js";
import { MINUTES } from "../../utils.js";
import { requireGuildPermission } from "../permissions.js";
import { rateLimit } from "../rateLimits.js";
import { clientError, ok } from "../responses.js";

const caseHandlingModeSchema = z.union([
z.literal("replace"),
Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/guilds/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from "express";
import { apiTokenAuthHandlers } from "../auth";
import { initGuildsImportExportAPI } from "./importExport";
import { initGuildsMiscAPI } from "./misc";
import { apiTokenAuthHandlers } from "../auth.js";
import { initGuildsImportExportAPI } from "./importExport.js";
import { initGuildsMiscAPI } from "./misc.js";

export function initGuildsAPI(router: express.Router) {
const guildRouter = express.Router();
Expand Down
30 changes: 16 additions & 14 deletions backend/src/api/guilds/misc.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { ApiPermissions } from "@zeppelinbot/shared";
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import express, { Request, Response } from "express";
import { YAMLException } from "js-yaml";
import jsYaml from "js-yaml";
import moment from "moment-timezone";
import { Queue } from "../../Queue";
import { validateGuildConfig } from "../../configValidator";
import { AllowedGuilds } from "../../data/AllowedGuilds";
import { ApiAuditLog } from "../../data/ApiAuditLog";
import { ApiPermissionAssignments, ApiPermissionTypes } from "../../data/ApiPermissionAssignments";
import { Configs } from "../../data/Configs";
import { AuditLogEventTypes } from "../../data/apiAuditLogTypes";
import { isSnowflake } from "../../utils";
import { loadYamlSafely } from "../../utils/loadYamlSafely";
import { ObjectAliasError } from "../../utils/validateNoObjectAliases";
import { hasGuildPermission, requireGuildPermission } from "../permissions";
import { clientError, ok, serverError, unauthorized } from "../responses";
import { Queue } from "../../Queue.js";
import { validateGuildConfig } from "../../configValidator.js";
import { AllowedGuilds } from "../../data/AllowedGuilds.js";
import { ApiAuditLog } from "../../data/ApiAuditLog.js";
import { ApiPermissionAssignments, ApiPermissionTypes } from "../../data/ApiPermissionAssignments.js";
import { Configs } from "../../data/Configs.js";
import { AuditLogEventTypes } from "../../data/apiAuditLogTypes.js";
import { isSnowflake } from "../../utils.js";
import { loadYamlSafely } from "../../utils/loadYamlSafely.js";
import { ObjectAliasError } from "../../utils/validateNoObjectAliases.js";
import { hasGuildPermission, requireGuildPermission } from "../permissions.js";
import { clientError, ok, serverError, unauthorized } from "../responses.js";

const YAMLException = jsYaml.YAMLException;

const apiPermissionAssignments = new ApiPermissionAssignments();
const auditLog = new ApiAuditLog();
Expand Down
8 changes: 4 additions & 4 deletions backend/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// KEEP THIS AS FIRST IMPORT
// See comment in module for details
import "../threadsSignalFix";
import "../threadsSignalFix.js";

import { connect } from "../data/db";
import { env } from "../env";
import { setIsAPI } from "../globals";
import { connect } from "../data/db.js";
import { env } from "../env.js";
import { setIsAPI } from "../globals.js";

if (!env.KEY) {
// tslint:disable-next-line:no-console
Expand Down
8 changes: 4 additions & 4 deletions backend/src/api/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApiPermissions, hasPermission, permissionArrToSet } from "@zeppelinbot/shared";
import { ApiPermissions, hasPermission, permissionArrToSet } from "@zeppelinbot/shared/apiPermissions.js";
import { Request, Response } from "express";
import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments";
import { isStaff } from "../staff";
import { unauthorized } from "./responses";
import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments.js";
import { isStaff } from "../staff.js";
import { unauthorized } from "./responses.js";

const apiPermissionAssignments = new ApiPermissionAssignments();

Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/rateLimits.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import { error } from "./responses";
import { error } from "./responses.js";

const lastRequestsByKey: Map<string, number> = new Map();

Expand Down
4 changes: 2 additions & 2 deletions backend/src/api/staff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express, { Request, Response } from "express";
import { isStaff } from "../staff";
import { apiTokenAuthHandlers } from "./auth";
import { isStaff } from "../staff.js";
import { apiTokenAuthHandlers } from "./auth.js";

export function initStaff(app: express.Express) {
const staffRouter = express.Router();
Expand Down
14 changes: 7 additions & 7 deletions backend/src/api/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import cors from "cors";
import express from "express";
import multer from "multer";
import { TokenError } from "passport-oauth2";
import { env } from "../env";
import { initArchives } from "./archives";
import { initAuth } from "./auth";
import { initDocs } from "./docs";
import { initGuildsAPI } from "./guilds/index";
import { clientError, error, notFound } from "./responses";
import { startBackgroundTasks } from "./tasks";
import { env } from "../env.js";
import { initArchives } from "./archives.js";
import { initAuth } from "./auth.js";
import { initDocs } from "./docs.js";
import { initGuildsAPI } from "./guilds/index.js";
import { clientError, error, notFound } from "./responses.js";
import { startBackgroundTasks } from "./tasks.js";

const apiPathPrefix = env.API_PATH_PREFIX || (env.NODE_ENV === "development" ? "/api" : "");

Expand Down
4 changes: 2 additions & 2 deletions backend/src/api/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments";
import { MINUTES } from "../utils";
import { ApiPermissionAssignments } from "../data/ApiPermissionAssignments.js";
import { MINUTES } from "../utils.js";

export function startBackgroundTasks() {
// Clear expired API permissions every minute
Expand Down
6 changes: 3 additions & 3 deletions backend/src/commandTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
resolveUserId,
roleMentionRegex,
UnknownUser,
} from "./utils";
import { isValidTimezone } from "./utils/isValidTimezone";
import { MessageTarget, resolveMessageTarget } from "./utils/resolveMessageTarget";
} from "./utils.js";
import { isValidTimezone } from "./utils/isValidTimezone.js";
import { MessageTarget, resolveMessageTarget } from "./utils/resolveMessageTarget.js";

export const commandTypes = {
...messageCommandBaseTypeConverters,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/configValidator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConfigValidationError, GuildPluginBlueprint, PluginConfigManager } from "knub";
import moment from "moment-timezone";
import { ZodError } from "zod";
import { guildPlugins } from "./plugins/availablePlugins";
import { ZeppelinGuildConfig, zZeppelinGuildConfig } from "./types";
import { formatZodIssue } from "./utils/formatZodIssue";
import { guildPlugins } from "./plugins/availablePlugins.js";
import { ZeppelinGuildConfig, zZeppelinGuildConfig } from "./types.js";
import { formatZodIssue } from "./utils/formatZodIssue.js";

const pluginNameToPlugin = new Map<string, GuildPluginBlueprint<any, any>>();
for (const plugin of guildPlugins) {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/data/AllowedGuilds.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import moment from "moment-timezone";
import { Repository } from "typeorm";
import { DBDateFormat } from "../utils";
import { ApiPermissionTypes } from "./ApiPermissionAssignments";
import { BaseRepository } from "./BaseRepository";
import { dataSource } from "./dataSource";
import { AllowedGuild } from "./entities/AllowedGuild";
import { DBDateFormat } from "../utils.js";
import { ApiPermissionTypes } from "./ApiPermissionAssignments.js";
import { BaseRepository } from "./BaseRepository.js";
import { dataSource } from "./dataSource.js";
import { AllowedGuild } from "./entities/AllowedGuild.js";

export class AllowedGuilds extends BaseRepository {
private allowedGuilds: Repository<AllowedGuild>;
Expand Down
10 changes: 5 additions & 5 deletions backend/src/data/ApiAuditLog.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Repository } from "typeorm/index";
import { BaseRepository } from "./BaseRepository";
import { AuditLogEventData, AuditLogEventType } from "./apiAuditLogTypes";
import { dataSource } from "./dataSource";
import { ApiAuditLogEntry } from "./entities/ApiAuditLogEntry";
import { Repository } from "typeorm";
import { BaseRepository } from "./BaseRepository.js";
import { AuditLogEventData, AuditLogEventType } from "./apiAuditLogTypes.js";
import { dataSource } from "./dataSource.js";
import { ApiAuditLogEntry } from "./entities/ApiAuditLogEntry.js";

export class ApiAuditLog extends BaseRepository {
private auditLog: Repository<ApiAuditLogEntry<any>>;
Expand Down
8 changes: 4 additions & 4 deletions backend/src/data/ApiLogins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import moment from "moment-timezone";
import { Repository } from "typeorm";
// tslint:disable-next-line:no-submodule-imports
import { v4 as uuidv4 } from "uuid";
import { DAYS, DBDateFormat } from "../utils";
import { BaseRepository } from "./BaseRepository";
import { dataSource } from "./dataSource";
import { ApiLogin } from "./entities/ApiLogin";
import { DAYS, DBDateFormat } from "../utils.js";
import { BaseRepository } from "./BaseRepository.js";
import { dataSource } from "./dataSource.js";
import { ApiLogin } from "./entities/ApiLogin.js";

const LOGIN_EXPIRY_TIME = 1 * DAYS;

Expand Down
12 changes: 6 additions & 6 deletions backend/src/data/ApiPermissionAssignments.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApiPermissions } from "@zeppelinbot/shared";
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import { Repository } from "typeorm";
import { ApiAuditLog } from "./ApiAuditLog";
import { BaseRepository } from "./BaseRepository";
import { AuditLogEventTypes } from "./apiAuditLogTypes";
import { dataSource } from "./dataSource";
import { ApiPermissionAssignment } from "./entities/ApiPermissionAssignment";
import { ApiAuditLog } from "./ApiAuditLog.js";
import { BaseRepository } from "./BaseRepository.js";
import { AuditLogEventTypes } from "./apiAuditLogTypes.js";
import { dataSource } from "./dataSource.js";
import { ApiPermissionAssignment } from "./entities/ApiPermissionAssignment.js";

export enum ApiPermissionTypes {
User = "USER",
Expand Down
Loading

0 comments on commit 2c6b176

Please sign in to comment.