Skip to content

Commit

Permalink
feat: adding husky precommit and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 11, 2024
1 parent 14b2fc1 commit ef516bd
Show file tree
Hide file tree
Showing 19 changed files with 412 additions and 387 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bun format
bun test
36 changes: 22 additions & 14 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"lineWidth": 100
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignoreUnknown": true,
"ignore": ["dist/**"]
},
"json": {
"formatter": {
"enabled": true
}
},
"formatter": {
"formatWithErrors": true,
"indentStyle": "space",
"enabled": true,
"lineWidth": 100
},
"linter": {
"enabled": true
}
}
Binary file modified bun.lockb
Binary file not shown.
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "topsort.js",
"version": "1.0.0",
"description": "",
"private": true,
"packageManager": "[email protected]",
"main": "src/index.ts",
"author": "Márcio Barbosa <[email protected]>",
"license": "UNLICENSED",
"scripts": {
"build": "bun build",
"test": "bun test",
"doctest": "bun run src/lib/doctest.test.ts",
"format": "biome check",
"format:fix": "biome check --write"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@supabase/doctest-js": "^0.1.0",
"@types/bun": "^1.1.6",
"msw": "^2.3.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {}
"name": "topsort.js",
"version": "1.0.0",
"description": "",
"private": true,
"packageManager": "[email protected]",
"main": "src/index.ts",
"author": "Márcio Barbosa <[email protected]>",
"license": "UNLICENSED",
"scripts": {
"build": "bun build",
"test": "bun test",
"doctest": "bun run src/lib/doctest.test.ts",
"format": "biome check",
"format:fix": "biome check --write"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@supabase/doctest-js": "^0.1.0",
"@types/bun": "^1.1.6",
"msw": "^2.3.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {}
}
4 changes: 2 additions & 2 deletions src/constants/apis.constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const baseURL = "https://api.topsort.com";

export const apis = {
auctions: "v2/auctions",
events: "v2/events",
auctions: "v2/auctions",
events: "v2/events",
};
22 changes: 11 additions & 11 deletions src/constants/handlers.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { apis, baseURL } from "./apis.constant";
const errorBaseURL = "https://error.api.topsort.com/";

export const handlers = {
events: http.post(`${baseURL}/${apis.events}`, () => {
return HttpResponse.json({}, { status: 200 });
}),
eventsError: http.post(`${errorBaseURL}/${apis.events}`, () => {
return HttpResponse.error();
}),
events: http.post(`${baseURL}/${apis.events}`, () => {
return HttpResponse.json({}, { status: 200 });
}),
eventsError: http.post(`${errorBaseURL}/${apis.events}`, () => {
return HttpResponse.error();
}),
};

export const returnStatus = (status: number, server: SetupServerApi, url: string) => {
return server.use(
http.post(url, () => {
return HttpResponse.json({}, { status: status });
}),
);
return server.use(
http.post(url, () => {
return HttpResponse.json({}, { status: status });
}),
);
};
21 changes: 9 additions & 12 deletions src/functions/create-auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import type { AuctionResult, TopsortAuction } from "../interfaces/auctions.inter
import type { Config } from "../interfaces/shared.interface";
import APIClient from "../lib/api-client";

export async function createAuction(
body: TopsortAuction,
config: Config,
): Promise<AuctionResult> {
let url: URL;
try {
url = new URL(`${config.host || baseURL}/${apis.auctions}`);
} catch (error) {
throw new Error(`Invalid URL: ${config.host || baseURL}/${apis.auctions}`);
}
export async function createAuction(body: TopsortAuction, config: Config): Promise<AuctionResult> {
let url: URL;
try {
url = new URL(`${config.host || baseURL}/${apis.auctions}`);
} catch (error) {
throw new Error(`Invalid URL: ${config.host || baseURL}/${apis.auctions}`);
}

const result = await APIClient.post(url.toString(), body, config);
return result as AuctionResult;
const result = await APIClient.post(url.toString(), body, config);
return result as AuctionResult;
}
25 changes: 11 additions & 14 deletions src/functions/report-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ import APIClient from "../lib/api-client";
* @param config - The configuration object containing URL and token.
* @returns {Promise<{ok: boolean}>} The result of the report, indicating success and if a retry is needed.
*/
export async function reportEvent(
event: TopsortEvent,
config: Config,
): Promise<{ ok: boolean }> {
let url: URL;
try {
url = new URL(`${config.host || baseURL}/${apis.events}`);
} catch (error) {
throw new Error(`Invalid URL: ${config.host || baseURL}/${apis.events}`);
}
export async function reportEvent(event: TopsortEvent, config: Config): Promise<{ ok: boolean }> {
let url: URL;
try {
url = new URL(`${config.host || baseURL}/${apis.events}`);
} catch (error) {
throw new Error(`Invalid URL: ${config.host || baseURL}/${apis.events}`);
}

await APIClient.post(url.toString(), event, config);
await APIClient.post(url.toString(), event, config);

return {
ok: true,
};
return {
ok: true,
};
}
56 changes: 28 additions & 28 deletions src/interfaces/auctions.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,67 @@ type AuctionType = "banners" | "listings";
type DeviceType = "desktop" | "mobile";

interface GeoTargeting {
location: string;
location: string;
}

interface AuctionSingleCategory {
id: string;
id: string;
}

interface AuctionMultipleCategories {
ids: string[];
ids: string[];
}

interface AuctionDisjunctiveCategories {
disjunctions: string[][];
disjunctions: string[][];
}

interface AuctionProduct {
ids: string[];
qualityScores: number[];
ids: string[];
qualityScores: number[];
}

interface AuctionBase {
type: AuctionType;
slots: number;
category?: AuctionSingleCategory | AuctionMultipleCategories | AuctionDisjunctiveCategories;
searchQuery?: string;
products?: AuctionProduct;
geoTargeting?: GeoTargeting;
type: AuctionType;
slots: number;
category?: AuctionSingleCategory | AuctionMultipleCategories | AuctionDisjunctiveCategories;
searchQuery?: string;
products?: AuctionProduct;
geoTargeting?: GeoTargeting;
}

interface SponsoredListingAuction extends AuctionBase {
type: "listings";
type: "listings";
}

interface BannerAuction extends AuctionBase {
type: "banners";
device: DeviceType;
slotId: string;
type: "banners";
device: DeviceType;
slotId: string;
}

export interface TopsortAuction {
auctions: (SponsoredListingAuction | BannerAuction)[];
auctions: (SponsoredListingAuction | BannerAuction)[];
}

interface Asset {
url: string;
url: string;
}

interface Winner {
rank: number;
asset: Asset[];
type: string;
id: string;
resolvedBidId: string;
rank: number;
asset: Asset[];
type: string;
id: string;
resolvedBidId: string;
}

interface Result {
resultType: AuctionType;
winners: Winner[];
error: boolean;
resultType: AuctionType;
winners: Winner[];
error: boolean;
}

export interface AuctionResult {
results: Result[];
}
results: Result[];
}
54 changes: 27 additions & 27 deletions src/interfaces/events.interface.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
interface Placement {
path: string;
path: string;
}

export interface Entity {
type: "product";
id: string;
type: "product";
id: string;
}

interface Impression {
resolvedBidId?: string;
entity?: Entity;
additionalAttribution?: Entity;
placement: Placement;
occurredAt: string;
opaqueUserId: string;
id: string;
resolvedBidId?: string;
entity?: Entity;
additionalAttribution?: Entity;
placement: Placement;
occurredAt: string;
opaqueUserId: string;
id: string;
}

interface Click {
resolvedBidId?: string;
entity?: Entity;
additionalAttribution?: Entity;
placement: Placement;
occurredAt: string;
opaqueUserId: string;
id: string;
resolvedBidId?: string;
entity?: Entity;
additionalAttribution?: Entity;
placement: Placement;
occurredAt: string;
opaqueUserId: string;
id: string;
}

interface Item {
productId: string;
quantity: number;
unitPrice: number;
productId: string;
quantity: number;
unitPrice: number;
}

interface Purchase {
occurredAt: string;
opaqueUserId: string;
id: string;
items: Item[];
occurredAt: string;
opaqueUserId: string;
id: string;
items: Item[];
}

export interface TopsortEvent {
impressions?: Impression[];
clicks?: Click[];
purchases?: Purchase[];
impressions?: Impression[];
clicks?: Click[];
purchases?: Purchase[];
}
4 changes: 2 additions & 2 deletions src/interfaces/shared.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Config {
apiKey: string;
host?: string;
apiKey: string;
host?: string;
}
Loading

0 comments on commit ef516bd

Please sign in to comment.