Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 20, 2024
1 parent 428f684 commit ac893c3
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
32 changes: 32 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@midday/sdk",
"description": "Midday SDK",
"version": "0.0.0-beta.1",
"private": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/midday-ai/midday"
},
"homepage": "https://midday.ai",
"publishConfig": {
"access": "public"
},
"files": ["dist"],
"scripts": {
"dev": "tsup tsup src/index.ts --format cjs,esm --dts --watch",
"build": "rm -rf dist && tsup src/index.ts --format cjs,esm --dts",
"npm:publish": "npm run build && npm publish",
"lint": "biome check .",
"check:types": "tsc --noEmit"
},
"devDependencies": {
"tsup": "^8.3.5",
"typescript": "^5.6.3"
},
"dependencies": {
"@supabase/supabase-js": "^2.46.1"
}
}
61 changes: 61 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Database } from "@midday/supabase/types";
import { type SupabaseClient, createClient } from "@supabase/supabase-js";
import {
Inbox,
Invoices,
Metrics,
Settings,
Tracker,
Transactions,
Vault,
} from "./resource";
import type { SDKOptions } from "./types";

const API_ENDPOINT = "https://api.midday.ai/v1";

export class Midday {
#options: SDKOptions;
#client: SupabaseClient<Database>;

public transactions: Transactions;
public invoices: Invoices;
public tracker: Tracker;
public inbox: Inbox;
public vault: Vault;
public metrics: Metrics;
public settings: Settings;

constructor(options: SDKOptions) {
this.#options = {
...options,
apiKey: options.apiKey || process.env.MIDDAY_API_KEY || "",
};

if (!this.#options.apiKey) {
throw new Error(
"You need to provide an API key, either via the constructor or the MIDDAY_API_KEY environment variable: https://docs.midday.ai/sdk",
);
}

this.#client = createClient(API_ENDPOINT, undefined, {
global: {
headers: {
Authorization: `Bearer ${this.#options.apiKey}`,
},
},
auth: {
persistSession: false,
detectSessionInUrl: false,
autoRefreshToken: false,
},
});

this.transactions = new Transactions(this.#client);
this.invoices = new Invoices(this.#client);
this.tracker = new Tracker(this.#client);
this.inbox = new Inbox(this.#client);
this.vault = new Vault(this.#client);
this.metrics = new Metrics(this.#client);
this.settings = new Settings(this.#client);
}
}
6 changes: 6 additions & 0 deletions packages/sdk/src/resource/inbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Inbox {
async list(): Promise<string[]> {
// Replace with API call logic
return ["Inbox 1", "Inbox 2"];
}
}
8 changes: 8 additions & 0 deletions packages/sdk/src/resource/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from "./invoices";
export * from "./transactions";
export * from "./tracker";
export * from "./inbox";
export * from "./vault";
export * from "./metrics";
export * from "./settings";
export * from "./team2";
6 changes: 6 additions & 0 deletions packages/sdk/src/resource/invoices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Invoices {
async list(): Promise<string[]> {
// Replace with API call logic
return ["Invoice 1", "Invoice 2"];
}
}
26 changes: 26 additions & 0 deletions packages/sdk/src/resource/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export class Metrics {
async burnRate(): Promise<number> {
// Replace with API call logic
return 0.5;
}

async runway(): Promise<number> {
// Replace with API call logic
return 1000;
}

async revenue(): Promise<number> {
// Replace with API call logic
return 1000;
}

async expenses(): Promise<number> {
// Replace with API call logic
return 500;
}

async profit(): Promise<number> {
// Replace with API call logic
return 500;
}
}
6 changes: 6 additions & 0 deletions packages/sdk/src/resource/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Settings {
async list(): Promise<string[]> {
// Replace with API call logic
return ["Setting 1", "Setting 2"];
}
}
11 changes: 11 additions & 0 deletions packages/sdk/src/resource/tracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class Tracker {
async list(): Promise<string[]> {
// Replace with API call logic
return ["Transaction 1", "Transaction 2"];
}

async updateById(id: string, data: any): Promise<string> {
// Replace with API call logic
return `Transaction ${id} updated`;
}
}
11 changes: 11 additions & 0 deletions packages/sdk/src/resource/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class Transactions {
async list(): Promise<string[]> {
// Replace with API call logic
return ["Transaction 1", "Transaction 2"];
}

async updateById(id: string, data: any): Promise<string> {
// Replace with API call logic
return `Transaction ${id} updated`;
}
}
6 changes: 6 additions & 0 deletions packages/sdk/src/resource/vault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Vault {
async list(): Promise<string[]> {
// Replace with API call logic
return ["File 1", "File 2"];
}
}
3 changes: 3 additions & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type SDKOptions = {
apiKey: string;
};
8 changes: 8 additions & 0 deletions packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@midday/tsconfig/base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["dist", "node_modules"]
}

0 comments on commit ac893c3

Please sign in to comment.