Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 7, 2024
1 parent 0f85cde commit 516880f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
Empty file.
61 changes: 59 additions & 2 deletions apps/engine/src/providers/pluggy/pluggy-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PluggyClient } from "pluggy-sdk";
import type { ProviderParams } from "../types";
import type { GetTransactionsParams } from "./types";

export class PluggyApi {
#client: PluggyClient;
Expand All @@ -16,7 +17,63 @@ export class PluggyApi {
});
}

async getAccounts(itemId: string) {
return this.#client.fetchAccounts(itemId);
#generateWebhookUrl(environment: "sandbox" | "production") {
if (environment === "sandbox") {
return "https://staging.app.midday.ai/api/webhook/pluggy";
}

return "https://app.midday.ai/api/webhook/pluggy";
}

async getAccounts(id: string) {
return this.#client.fetchAccounts(id);
}

async getTransactions({ accountId, latest }: GetTransactionsParams) {
if (latest) {
return this.#client.fetchTransactions(accountId);
}

return this.#client.fetchAllTransactions(accountId);
}

async getHealthCheck() {
// https://status.pluggy.ai/api/v2/status.json
// return this.#client.healthCheck();
}

async getAccountBalance({
accessToken,
accountId,
}: GetAccountBalanceRequest): Promise<
GetAccountBalanceResponse | undefined
> {}

async getInstitutions() {
return this.#client.fetchConnectors();
}

async getInstitutionById(id: string) {
return this.#client.fetchConnectorById(id);
}

async getConnectionStatus({ id }: GetConnectionStatusRequest) {
return this.#client.consentRetrieve(id);
}

async deleteAccounts() {}

async linkTokenCreate({
userId,
webhookUrl,
environment = "production",
}: LinkTokenCreateRequest) {
const { accessToken: connectToken } = await this.#client.createConnectToken(
ITEM_ID_TO_UPDATE,
{
clientUserId: userId,
webhook: this.#generateWebhookUrl(environment),
},
);
}
}
4 changes: 4 additions & 0 deletions apps/engine/src/providers/pluggy/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type GetTransactionsParams = {
accountId: string;
latest?: boolean;
};

0 comments on commit 516880f

Please sign in to comment.