diff --git a/packages/bsky/package.json b/packages/bsky/package.json index 74a36cf2ac2..9b8b3f8f482 100644 --- a/packages/bsky/package.json +++ b/packages/bsky/package.json @@ -41,7 +41,6 @@ "@connectrpc/connect-express": "^1.1.4", "@connectrpc/connect-node": "^1.1.4", "@did-plc/lib": "^0.0.1", - "axios": "^0.27.2", "compression": "^1.7.4", "cors": "^2.8.5", "express": "^4.17.2", @@ -77,6 +76,7 @@ "@types/express-serve-static-core": "^4.17.36", "@types/pg": "^8.6.6", "@types/qs": "^6.9.7", + "axios": "^0.27.2", "jest": "^28.1.2", "ts-node": "^10.8.2", "typescript": "^5.6.3" diff --git a/packages/bsky/src/revenueCat.ts b/packages/bsky/src/revenueCat.ts index 32f494ac0ef..55455f0075b 100644 --- a/packages/bsky/src/revenueCat.ts +++ b/packages/bsky/src/revenueCat.ts @@ -1,5 +1,3 @@ -import axios, { AxiosInstance } from 'axios' - type Config = { apiKey: string url: string @@ -15,26 +13,38 @@ type GetSubscriberResponse = { } export class RevenueCatClient { + private apiKey: string + private url: string private webhookAuthorization: string | undefined - private axios: AxiosInstance constructor({ apiKey, url, webhookAuthorization }: Config) { - this.axios = axios.create({ - baseURL: url, + this.apiKey = apiKey + this.url = url + this.webhookAuthorization = webhookAuthorization + } + + private async fetch( + path: string, + method: string = 'GET', + ): Promise { + const res = await fetch(`${this.url}${path}`, { + method, headers: { - Authorization: `Bearer ${apiKey}`, + Authorization: `Bearer ${this.apiKey}`, }, }) - this.webhookAuthorization = webhookAuthorization + if (!res.ok) { + throw new Error(`Failed to fetch ${path}: ${res.statusText}`) + } + + return res.json() as T } async getSubscriber(did: string): Promise { - const { data } = await this.axios.get( + return this.fetch( `/subscribers/${encodeURIComponent(did)}`, ) - - return data as GetSubscriberResponse } isWebhookAuthorizationValid(authorization: string | undefined): boolean { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e70f371b6f..424882fc84c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -190,9 +190,6 @@ importers: '@did-plc/lib': specifier: ^0.0.1 version: 0.0.1 - axios: - specifier: ^0.27.2 - version: 0.27.2 compression: specifier: ^1.7.4 version: 1.7.4 @@ -290,6 +287,9 @@ importers: '@types/qs': specifier: ^6.9.7 version: 6.9.7 + axios: + specifier: ^0.27.2 + version: 0.27.2 jest: specifier: ^28.1.2 version: 28.1.2(@types/node@18.19.56)(ts-node@10.8.2)