Skip to content

Commit

Permalink
Merge branch 'main' into evan/updown
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaque committed Sep 11, 2024
2 parents 6221e52 + 02e49ae commit af2a771
Show file tree
Hide file tree
Showing 20 changed files with 3,019 additions and 2,672 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CLI (Check)

on: [push]

jobs:
# run format, lint, and test
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- run: bun check
Binary file modified bun.lockb
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"scripts": {
"format": "biome format --write ./src",
"lint": "biome lint --write ./src",
"check": "biome check ./src",
"check-fix": "biome check ./src --apply",
"check": "biome check ./src && tsc --noEmit --project .",
"dev": "IS_DEVELOPMENT_CLI_ENV=true bun run src/index.ts",
"release": "bun run src/scripts/release.ts",
"prod": "bun run src/index.ts",
Expand All @@ -28,7 +29,7 @@
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
"typescript": "^5.6.2"
},
"version": "0.0.28"
"version": "0.0.30"
}
47 changes: 0 additions & 47 deletions src/api/index.ts

This file was deleted.

90 changes: 0 additions & 90 deletions src/api/orders.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/api/quoting.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/api/types.ts

This file was deleted.

14 changes: 11 additions & 3 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import createClient from "openapi-fetch";
import createClient, { type Client } from "openapi-fetch";
import { getAuthToken, loadConfig } from "./helpers/config";
import type { paths } from "./schema"; // generated by openapi-typescript

let __client: Client<paths, `${string}/${string}`> | undefined;

export const apiClient = async () => {
const config = await loadConfig();
if (__client) {
return __client;
}

return createClient<paths>({
const config = await loadConfig();
__client = createClient<paths>({
baseUrl: config.api_url,
headers: {
Authorization: `Bearer ${await getAuthToken()}`,
"Content-Type": "application/json",
},
});

return __client;
};
8 changes: 4 additions & 4 deletions src/helpers/errors.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { getCommandBase } from "./command";
import { clearAuthFromConfig } from "./config";

export function logAndQuit(message: string) {
export function logAndQuit(message: string): never {
console.error(message);
process.exit(1);
}

export function logLoginMessageAndQuit() {
export function logLoginMessageAndQuit(): never {
const base = getCommandBase();
const loginCommand = `${base} login`;

logAndQuit(`You need to login first.\n\n\t$ ${loginCommand}\n`);
}

export async function logSessionTokenExpiredAndQuit() {
export async function logSessionTokenExpiredAndQuit(): Promise<never> {
await clearAuthFromConfig();
logAndQuit("\nYour session has expired. Please login again.");
}

export function failedToConnect() {
export function failedToConnect(): never {
logAndQuit(
"Failed to connect to the server. Please check your internet connection and try again.",
);
Expand Down
40 changes: 38 additions & 2 deletions src/helpers/units.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
import type { Nullable } from "../types/empty";

// -- time

export type Epoch = number;

const MILLS_PER_EPOCH = 1000 * 60; // 1 minute
const EPOCHS_PER_HOUR = (3600 * 1000) / MILLS_PER_EPOCH;

export function currentEpoch(): Epoch {
return Math.floor(Date.now() / MILLS_PER_EPOCH);
}

export function epochToDate(epoch: Epoch): Date {
return new Date(epoch * MILLS_PER_EPOCH);
}

export function roundStartDate(startDate: Date): Date {
const now = currentEpoch();
const startEpoch = dateToEpoch(startDate);
if (startEpoch <= now + 1) {
return epochToDate(now + 1);
} else {
return epochToDate(roundEpochUpToHour(startEpoch));
}
}

export function roundEndDate(endDate: Date): Date {
return epochToDate(roundEpochUpToHour(dateToEpoch(endDate)));
}

function dateToEpoch(date: Date): number {
return Math.ceil(date.getTime() / MILLS_PER_EPOCH);
}
function roundEpochUpToHour(epoch: number): number {
return Math.ceil(epoch / EPOCHS_PER_HOUR) * EPOCHS_PER_HOUR;
}

// -- currency

export type Cents = number;
export type Centicents = number;

// --

interface PriceWholeToCenticentsReturn {
centicents: Nullable<Centicents>;
invalid: boolean;
Expand Down
Loading

0 comments on commit af2a771

Please sign in to comment.