- Add `writeSupplierWorkbook` function to create Excel workbooks for supplier analysis results. - Introduce `SupplierExportSummary` type for summarizing export data. - Create tests for `writeSupplierWorkbook` to ensure correct sheet creation and data population. - Implement supplier scoring logic in `supplier-scoring.ts` to evaluate product profitability and demand. - Add tests for supplier scoring to validate scoring logic and verdict determination. - Enhance UPC file analysis to integrate supplier scoring and export results to Excel. - Update database writing logic to accommodate new supplier analysis results. - Refactor types to include supplier-specific data structures and scoring metrics. - Ensure proper cleanup of temporary files after tests.
123 lines
3.7 KiB
Markdown
123 lines
3.7 KiB
Markdown
|
|
Default to using Bun instead of Node.js.
|
|
|
|
- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
|
|
- Use `bun test` instead of `jest` or `vitest`
|
|
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
|
|
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
|
|
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
|
|
- Use `bunx <package> <command>` instead of `npx <package> <command>`
|
|
- Bun automatically loads .env, so don't use dotenv.
|
|
|
|
## APIs
|
|
|
|
- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
|
|
- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
|
|
- `Bun.redis` for Redis. Don't use `ioredis`.
|
|
- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
|
|
- `WebSocket` is built-in. Don't use `ws`.
|
|
- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
|
|
- Bun.$`ls` instead of execa.
|
|
|
|
## Testing
|
|
|
|
Use `bun test` to run tests.
|
|
|
|
For this project, also use TypeScript's local compiler for type-checking:
|
|
|
|
```sh
|
|
./node_modules/.bin/tsc --noEmit
|
|
```
|
|
|
|
```ts#index.test.ts
|
|
import { test, expect } from "bun:test";
|
|
|
|
test("hello world", () => {
|
|
expect(1).toBe(1);
|
|
});
|
|
```
|
|
|
|
## Frontend
|
|
|
|
Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
|
|
|
|
Server:
|
|
|
|
```ts#index.ts
|
|
import index from "./index.html"
|
|
|
|
Bun.serve({
|
|
routes: {
|
|
"/": index,
|
|
"/api/users/:id": {
|
|
GET: (req) => {
|
|
return new Response(JSON.stringify({ id: req.params.id }));
|
|
},
|
|
},
|
|
},
|
|
// optional websocket support
|
|
websocket: {
|
|
open: (ws) => {
|
|
ws.send("Hello, world!");
|
|
},
|
|
message: (ws, message) => {
|
|
ws.send(message);
|
|
},
|
|
close: (ws) => {
|
|
// handle close
|
|
}
|
|
},
|
|
development: {
|
|
hmr: true,
|
|
console: true,
|
|
}
|
|
})
|
|
```
|
|
|
|
HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
|
|
|
|
```html#index.html
|
|
<html>
|
|
<body>
|
|
<h1>Hello, world!</h1>
|
|
<script type="module" src="./frontend.tsx"></script>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
With the following `frontend.tsx`:
|
|
|
|
```tsx#frontend.tsx
|
|
import React from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
|
|
// import .css files directly and it works
|
|
import './index.css';
|
|
|
|
const root = createRoot(document.body);
|
|
|
|
export default function Frontend() {
|
|
return <h1>Hello, world!</h1>;
|
|
}
|
|
|
|
root.render(<Frontend />);
|
|
```
|
|
|
|
Then, run index.ts
|
|
|
|
```sh
|
|
bun --hot ./index.ts
|
|
```
|
|
|
|
For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.
|
|
|
|
## asin-check Project Notes
|
|
|
|
- Keep the existing ASIN lead-list and category flows compatible with their current LLM-based FBA/FBM/SKIP analysis.
|
|
- The supplier UPC workflow is deterministic and runs through `bun run upc-file --input input/supplier.xlsx --out output/supplier_ranked.xlsx`.
|
|
- Keep supplier spreadsheets in `input/`, generated workbooks in `output/`, and SQLite files in `db/`; folder contents are ignored by git.
|
|
- Supplier UPC files should resolve UPC/EAN values through SP-API catalog lookup first, with Keepa UPC lookup only as fallback for no-match or request-failure cases.
|
|
- The supplier pipeline should not call LM Studio. It should enrich with Keepa + SP-API sellability/fees, score BUY/WATCH/SKIP numerically, write an Excel workbook, and persist rows to SQLite.
|
|
- Supplier workbook output should keep the `Ranked Leads`, `Skipped`, and `Summary` sheets.
|
|
- When changing UPC supplier behavior, cover SP-API UPC parsing, deterministic scoring, and workbook export with `bun test`.
|