Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit e51a168

Browse files
committed
dist
1 parent 84dea06 commit e51a168

155 files changed

Lines changed: 10663 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dist/app.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import express from 'express';
2+
import 'reflect-metadata';
3+
import './controllers/AuthenticatorController';
4+
import './controllers/BuyOrderController';
5+
import './controllers/DescribeController';
6+
import './controllers/GameController';
7+
import './controllers/GameGiftController';
8+
import './controllers/InventoryController';
9+
import './controllers/ItemController';
10+
import './controllers/LobbyController';
11+
import './controllers/MarketListingController';
12+
import './controllers/OAuth2Controller';
13+
import './controllers/SearchController';
14+
import './controllers/StripeController';
15+
import './controllers/StudioController';
16+
import './controllers/TradeController';
17+
import './controllers/UserController';
18+
import './controllers/WebAuthnController';
19+
export declare const app: express.Application;

dist/app.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.app = void 0;
7+
const compression_1 = __importDefault(require("compression"));
8+
const cors_1 = __importDefault(require("cors"));
9+
const dotenv_1 = require("dotenv");
10+
const express_1 = __importDefault(require("express"));
11+
const inversify_express_utils_1 = require("inversify-express-utils");
12+
require("reflect-metadata");
13+
const container_1 = __importDefault(require("./container"));
14+
(0, dotenv_1.config)();
15+
require("./controllers/AuthenticatorController");
16+
require("./controllers/BuyOrderController");
17+
require("./controllers/DescribeController");
18+
require("./controllers/GameController");
19+
require("./controllers/GameGiftController");
20+
require("./controllers/InventoryController");
21+
require("./controllers/ItemController");
22+
require("./controllers/LobbyController");
23+
require("./controllers/MarketListingController");
24+
require("./controllers/OAuth2Controller");
25+
require("./controllers/SearchController");
26+
require("./controllers/StripeController");
27+
require("./controllers/StudioController");
28+
require("./controllers/TradeController");
29+
require("./controllers/UserController");
30+
require("./controllers/WebAuthnController");
31+
const server = new inversify_express_utils_1.InversifyExpressServer(container_1.default);
32+
server.setConfig(app => {
33+
app.use('/stripe/webhook', express_1.default.raw({ type: 'application/json' }));
34+
app.use(express_1.default.json({ limit: '50mb' }));
35+
app.use(express_1.default.urlencoded({ limit: '50mb', extended: true }));
36+
app.use((0, cors_1.default)());
37+
app.use((0, compression_1.default)({
38+
threshold: 1024, // Compress responses larger than 1KB
39+
}));
40+
});
41+
server.setErrorConfig(app => {
42+
app.use((req, res) => {
43+
res.status(404).json({ message: 'Not Found' });
44+
});
45+
});
46+
exports.app = server.build();

dist/container.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Container } from 'inversify';
2+
declare const container: Container;
3+
export default container;

dist/container.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const inversify_1 = require("inversify");
4+
const BadgeService_1 = require("./services/BadgeService");
5+
const BuyOrderService_1 = require("./services/BuyOrderService");
6+
const DatabaseService_1 = require("./services/DatabaseService");
7+
const GameGiftService_1 = require("./services/GameGiftService");
8+
const GameService_1 = require("./services/GameService");
9+
const GameViewService_1 = require("./services/GameViewService");
10+
const InventoryService_1 = require("./services/InventoryService");
11+
const ItemService_1 = require("./services/ItemService");
12+
const LobbyService_1 = require("./services/LobbyService");
13+
const LogService_1 = require("./services/LogService");
14+
const MailService_1 = require("./services/MailService");
15+
const MarketListingService_1 = require("./services/MarketListingService");
16+
const OAuth2Service_1 = require("./services/OAuth2Service");
17+
const SteamOAuthService_1 = require("./services/SteamOAuthService");
18+
const StudioService_1 = require("./services/StudioService");
19+
const TradeService_1 = require("./services/TradeService");
20+
const UserService_1 = require("./services/UserService");
21+
const container = new inversify_1.Container();
22+
container.bind('DatabaseService').to(DatabaseService_1.DatabaseService).inSingletonScope();
23+
container.bind('InventoryService').to(InventoryService_1.InventoryService).inSingletonScope();
24+
container.bind('ItemService').to(ItemService_1.ItemService).inSingletonScope();
25+
container.bind('UserService').to(UserService_1.UserService).inSingletonScope();
26+
container.bind('LobbyService').to(LobbyService_1.LobbyService).inSingletonScope();
27+
container.bind('TradeService').to(TradeService_1.TradeService).inSingletonScope();
28+
container.bind('GameService').to(GameService_1.GameService).inSingletonScope();
29+
container.bind('OAuth2Service').to(OAuth2Service_1.OAuth2Service).inSingletonScope();
30+
container.bind('SteamOAuthService').to(SteamOAuthService_1.SteamOAuthService).inSingletonScope();
31+
container.bind('MailService').to(MailService_1.MailService).inSingletonScope();
32+
container.bind('StudioService').to(StudioService_1.StudioService).inSingletonScope();
33+
container.bind('LogService').to(LogService_1.LogService).inSingletonScope();
34+
container.bind('GameGiftService').to(GameGiftService_1.GameGiftService).inSingletonScope();
35+
container.bind('MarketListingService').to(MarketListingService_1.MarketListingService).inSingletonScope();
36+
container.bind('BuyOrderService').to(BuyOrderService_1.BuyOrderService).inSingletonScope();
37+
container.bind('BadgeService').to(BadgeService_1.BadgeService).inSingletonScope();
38+
container.bind('GameViewService').to(GameViewService_1.GameViewService).inSingletonScope();
39+
exports.default = container;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Request, Response } from 'express';
2+
import { AuthenticatedRequest } from '../middlewares/LoggedCheck';
3+
import { ILogService } from '../services/LogService';
4+
import { IUserService } from '../services/UserService';
5+
export declare class Authenticator {
6+
private userService;
7+
private logService;
8+
constructor(userService: IUserService, logService: ILogService);
9+
private logAction;
10+
verifyKey(req: Request, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
11+
handleAuthenticatorActions(req: AuthenticatedRequest, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
12+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22+
return c > 3 && r && Object.defineProperty(target, key, r), r;
23+
};
24+
var __importStar = (this && this.__importStar) || function (mod) {
25+
if (mod && mod.__esModule) return mod;
26+
var result = {};
27+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28+
__setModuleDefault(result, mod);
29+
return result;
30+
};
31+
var __param = (this && this.__param) || function (paramIndex, decorator) {
32+
return function (target, key) { decorator(target, key, paramIndex); }
33+
};
34+
Object.defineProperty(exports, "__esModule", { value: true });
35+
exports.Authenticator = void 0;
36+
const inversify_1 = require("inversify");
37+
const inversify_express_utils_1 = require("inversify-express-utils");
38+
const qrcode = __importStar(require("qrcode"));
39+
const time2fa_1 = require("time2fa");
40+
const LoggedCheck_1 = require("../middlewares/LoggedCheck");
41+
const GenKey_1 = require("../utils/GenKey");
42+
const Jwt_1 = require("../utils/Jwt");
43+
function handleError(res, error, message, status = 500) {
44+
const msg = error instanceof Error ? error.message : String(error);
45+
res.status(status).send({ message, error: msg });
46+
}
47+
let Authenticator = class Authenticator {
48+
constructor(userService, logService) {
49+
this.userService = userService;
50+
this.logService = logService;
51+
}
52+
async logAction(req, action, statusCode, metadata) {
53+
try {
54+
const requestBody = { ...req.body };
55+
if (metadata)
56+
requestBody.metadata = metadata;
57+
await this.logService.createLog({
58+
ip_address: req.headers['x-real-ip'] || req.socket.remoteAddress,
59+
table_name: 'authenticator',
60+
controller: `AuthenticatorController.${action}`,
61+
original_path: req.originalUrl,
62+
http_method: req.method,
63+
request_body: requestBody,
64+
user_id: req.user?.user_id,
65+
status_code: statusCode,
66+
});
67+
}
68+
catch (error) {
69+
console.error('Error creating log:', error);
70+
}
71+
}
72+
async verifyKey(req, res) {
73+
const { code, userId } = req.body;
74+
if (!userId) {
75+
await this.logAction(req, 'verifyKey', 400);
76+
return res.status(400).send({ message: 'User ID is required' });
77+
}
78+
try {
79+
const user = await this.userService.getUser(userId);
80+
if (!user) {
81+
await this.logAction(req, 'verifyKey', 404);
82+
return res.status(404).send({ message: 'User not found' });
83+
}
84+
const key = user.authenticator_secret;
85+
if (!key || !code) {
86+
await this.logAction(req, 'verifyKey', 400);
87+
return res.status(400).send({ message: 'Key and code are required' });
88+
}
89+
const isValid = time2fa_1.Totp.validate({ secret: key, passcode: code });
90+
if (isValid) {
91+
await this.logAction(req, 'verifyKey', 200);
92+
const apiKey = (0, GenKey_1.genKey)(user.user_id);
93+
const jwtToken = (0, Jwt_1.generateUserJwt)(user, apiKey);
94+
return res.status(200).send({ message: 'Key verified successfully', token: jwtToken });
95+
}
96+
else {
97+
await this.logAction(req, 'verifyKey', 400);
98+
return res.status(400).send({ message: 'Invalid key or code' });
99+
}
100+
}
101+
catch (error) {
102+
await this.logAction(req, 'verifyKey', 500, { error });
103+
handleError(res, error, 'Error verifying key');
104+
}
105+
}
106+
async handleAuthenticatorActions(req, res) {
107+
const action = req.params.action;
108+
const user = req.user;
109+
try {
110+
switch (action) {
111+
case 'generateKey': {
112+
if (!user || !user.email) {
113+
await this.logAction(req, 'generateKey', 400);
114+
return res.status(400).send({ message: 'User not authenticated or email missing' });
115+
}
116+
const key = time2fa_1.Totp.generateKey({ issuer: 'Croissant API', user: user.email });
117+
qrcode.toDataURL(key.url, async (err, url) => {
118+
if (err) {
119+
await this.logAction(req, 'generateKey', 500, { error: err });
120+
return res.status(500).send({ message: 'Error generating QR code' });
121+
}
122+
await this.logAction(req, 'generateKey', 200);
123+
res.status(200).send({ key, qrCode: url });
124+
});
125+
break;
126+
}
127+
case 'registerKey': {
128+
const { key: regKey, passcode } = req.body;
129+
if (!user || !user.email || !regKey) {
130+
await this.logAction(req, 'registerKey', 400);
131+
return res.status(400).send({ message: 'User not authenticated, email missing, or key missing' });
132+
}
133+
if (!passcode) {
134+
await this.logAction(req, 'registerKey', 400);
135+
return res.status(400).send({ message: 'Passcode is required' });
136+
}
137+
if (!time2fa_1.Totp.validate({ secret: regKey.secret, passcode })) {
138+
await this.logAction(req, 'registerKey', 400);
139+
return res.status(400).send({ message: 'Invalid passcode' });
140+
}
141+
await this.userService.setAuthenticatorSecret(user.user_id, regKey.secret);
142+
await this.logAction(req, 'registerKey', 200);
143+
res.status(200).send({ message: 'Key registered successfully' });
144+
break;
145+
}
146+
case 'delete': {
147+
if (!user || !user.email) {
148+
await this.logAction(req, 'deleteKey', 400);
149+
return res.status(400).send({ message: 'User not authenticated or email missing' });
150+
}
151+
await this.userService.setAuthenticatorSecret(user.user_id, null);
152+
await this.logAction(req, 'deleteKey', 200);
153+
res.status(200).send({ message: 'Google Authenticator deleted successfully' });
154+
break;
155+
}
156+
default:
157+
res.status(404).send({ message: 'Unknown action' });
158+
}
159+
}
160+
catch (error) {
161+
await this.logAction(req, action, 500, { error });
162+
handleError(res, error, `Error in ${action}`);
163+
}
164+
}
165+
};
166+
exports.Authenticator = Authenticator;
167+
__decorate([
168+
(0, inversify_express_utils_1.httpPost)('/verifyKey')
169+
], Authenticator.prototype, "verifyKey", null);
170+
__decorate([
171+
(0, inversify_express_utils_1.httpPost)('/:action', LoggedCheck_1.LoggedCheck.middleware)
172+
], Authenticator.prototype, "handleAuthenticatorActions", null);
173+
exports.Authenticator = Authenticator = __decorate([
174+
(0, inversify_express_utils_1.controller)('/authenticator'),
175+
__param(0, (0, inversify_1.inject)('UserService')),
176+
__param(1, (0, inversify_1.inject)('LogService'))
177+
], Authenticator);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Response } from 'express';
2+
import { AuthenticatedRequest } from '../middlewares/LoggedCheck';
3+
import { IBuyOrderService } from '../services/BuyOrderService';
4+
import { IItemService } from '../services/ItemService';
5+
import { ILogService } from '../services/LogService';
6+
export declare class BuyOrderController {
7+
private buyOrderService;
8+
private itemService;
9+
private logService;
10+
constructor(buyOrderService: IBuyOrderService, itemService: IItemService, logService: ILogService);
11+
private logAction;
12+
createBuyOrder(req: AuthenticatedRequest, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
13+
cancelBuyOrder(req: AuthenticatedRequest, res: Response): Promise<void>;
14+
getBuyOrdersByUser(req: AuthenticatedRequest, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
15+
getActiveBuyOrdersForItem(req: AuthenticatedRequest, res: Response): Promise<void>;
16+
}

0 commit comments

Comments
 (0)