Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Feb 26, 2024
1 parent fbe9232 commit 3a9fa69
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 403 deletions.
Binary file modified bun.lockb
Binary file not shown.
37 changes: 19 additions & 18 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"name": "@midday/providers",
"version": "1.0.0",
"main": "src/index.ts",
"private": true,
"sideEffects": false,
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "biome check .",
"format": "biome --write .",
"check:types": "tsc --noEmit"
},
"dependencies": {
"@midday/kv": "workspace:*",
"change-case": "^5.4.3"
},
"devDependencies": {
"typescript": "^5.3.3"
}
"name": "@midday/providers",
"version": "1.0.0",
"main": "src/index.ts",
"private": true,
"sideEffects": false,
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "biome check .",
"format": "biome --write .",
"check:types": "tsc --noEmit"
},
"dependencies": {
"@midday/kv": "workspace:*",
"axios": "^1.6.7",
"change-case": "^5.4.3"
},
"devDependencies": {
"typescript": "^5.3.3"
}
}
94 changes: 94 additions & 0 deletions packages/providers/src/gocardless/api/gocardless-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { client } from "@midday/kv";
import type { AxiosInstance, AxiosRequestConfig } from "axios";
import axios from "axios";
import { capitalCase } from "change-case";
import type {
AuthenticatedRequest,
GetAccountsResponse,
GetTransactionsRequest,
GetTransactionsResponse,
} from "./types";

const ONE_HOUR = 3600;
const ACCESS_VALID_FOR_DAYS = 180;
const MAX_HISTORICAL_DAYS = 730;

const keys = {
accessToken: "go_cardless_access_token_v2",
refreshToken: "go_cardless_refresh_token_v2",
banks: "go_cardless_banks",
};

export class GoCardLessApi {
private api: AxiosInstance | null = null;
private baseURL = "https://bankaccountdata.gocardless.com";

/**
* List accounts a user granted access to in Teller Connect
*
* https://teller.io/docs/api/accounts
*/

async getAccounts({
accessToken,
}: AuthenticatedRequest): Promise<GetAccountsResponse> {
const accounts = await this.get<GetAccountsResponse>(
"/accounts",
accessToken
);

return accounts;
}

/**
* Get transactions for a single account
*
* https://teller.io/docs/api/transactions
*/

async getTransactions({
accountId,
accessToken,
}: GetTransactionsRequest): Promise<GetTransactionsResponse> {
return this.get<GetTransactionsResponse>(
`/accounts/${accountId}/transactions`,
accessToken
);
}

private async getApi(accessToken: string): Promise<AxiosInstance> {
if (!this.api) {
this.api = axios.create({
baseURL: this.baseURL,
timeout: 30_000,
headers: {
Accept: "application/json",
},
auth: {
username: accessToken,
password: "",
},
});
} else if (this.api.defaults.auth?.username !== accessToken) {
this.api.defaults.auth = {
username: accessToken,
password: "",
};
}

return this.api;
}

/** Generic API GET request method */
private async get<TResponse>(
path: string,
accessToken: string,
params?: any,
config?: AxiosRequestConfig
): Promise<TResponse> {
const api = await this.getApi(accessToken);
return api
.get<TResponse>(path, { params, ...config })
.then(({ data }) => data);
}
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const ONE_HOUR = 3600;
const ACCESS_VALID_FOR_DAYS = 180;
const MAX_HISTORICAL_DAYS = 730;

enum balanceType {
interimBooked = "interimBooked",
interimAvailable = "interimAvailable",
}

const keys = {
accessToken: "go_cardless_access_token_v2",
refreshToken: "go_cardless_refresh_token_v2",
Expand Down
14 changes: 14 additions & 0 deletions packages/providers/src/shared/etl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface IETL<TInput, TExtracted = any, TTransformed = TExtracted> {
extract(input: TInput): Promise<TExtracted>;
transform(input: TInput, extracted: TExtracted): Promise<TTransformed>;
load(input: TInput, transformed: TTransformed): Promise<void>;
}

export async function etl<TInput, TExtracted, TTransformed>(
service: IETL<TInput, TExtracted, TTransformed>,
input: TInput
): Promise<void> {
const extracted = await service.extract(input);
const transformed = await service.transform(input, extracted);
await service.load(input, transformed);
}
235 changes: 0 additions & 235 deletions packages/providers/src/teller/api.ts

This file was deleted.

Loading

0 comments on commit 3a9fa69

Please sign in to comment.