diff --git a/src/base-command.ts b/src/base-command.ts index 8d6822c..f2e6d57 100644 --- a/src/base-command.ts +++ b/src/base-command.ts @@ -27,7 +27,7 @@ export default abstract class BaseCommand extends Base { public async getCurrentUser(): Promise { const apiKey = await ApiKeyStore.get() const apiClient = new APIClient(apiKey); - const user = await apiClient.user.getCurrent() + const user = await apiClient.users.getCurrent() return user; } diff --git a/src/core/api-client/index.ts b/src/core/api-client/index.ts index 320ad89..bda65c0 100644 --- a/src/core/api-client/index.ts +++ b/src/core/api-client/index.ts @@ -3,7 +3,8 @@ import ono from '@jsdevtools/ono'; import Apps from "./resources/apps"; import Deployments from "./resources/deployments"; import Diagnostics from "./resources/diagnostics"; -import User from "./resources/user"; +import Sellers from "./resources/sellers"; +import Users from "./resources/users"; export interface ApiClientParams { endpoint: string; @@ -37,7 +38,9 @@ export default class APIClient { diagnostics: Diagnostics; - user: User; + sellers: Sellers; + + users: Users; apiKey: string; @@ -49,7 +52,8 @@ export default class APIClient { this.apps = new Apps(this); this.deployments = new Deployments(this); this.diagnostics = new Diagnostics(this); - this.user = new User(this); + this.sellers = new Sellers(this); + this.users = new Users(this); } async call({ diff --git a/src/core/api-client/resources/sellers.ts b/src/core/api-client/resources/sellers.ts new file mode 100644 index 0000000..4ab32ac --- /dev/null +++ b/src/core/api-client/resources/sellers.ts @@ -0,0 +1,23 @@ +import { AppUser } from "../../types"; +import AppsAPIClient from '..'; + +export default class Sellers { + private client: AppsAPIClient; + + constructor(apiClient: AppsAPIClient) { + this.client = apiClient; + } + + /** + * Gets the current user for the given API key. + * @returns {Promise} Promise that resolves to an AppUser. + */ + async getCurrent(): Promise { + const response = await this.client.call({ + endpoint: "diagnostics/whoami", + method: "GET", + }); + + return response; + } +} diff --git a/src/core/api-client/resources/user.ts b/src/core/api-client/resources/users.ts similarity index 94% rename from src/core/api-client/resources/user.ts rename to src/core/api-client/resources/users.ts index 47b2df3..4ce14bd 100644 --- a/src/core/api-client/resources/user.ts +++ b/src/core/api-client/resources/users.ts @@ -1,7 +1,7 @@ import { AppUser } from "../../types"; import AppsAPIClient from '..'; -export default class User { +export default class Users { private client: AppsAPIClient; constructor(apiClient: AppsAPIClient) { diff --git a/test/specs/core/api-client.spec.js b/test/specs/core/api-client.spec.js index c6e0b31..5ca7f8f 100644 --- a/test/specs/core/api-client.spec.js +++ b/test/specs/core/api-client.spec.js @@ -564,7 +564,7 @@ describe("AppsApiClient @integration", () => { let errorResponse; try { - response = await validClient.user.getCurrent(); + response = await validClient.users.getCurrent(); } catch (error) { errorResponse = error; } @@ -578,7 +578,7 @@ describe("AppsApiClient @integration", () => { let errorResponse; try { - response = await invalidClient.user.getCurrent(); + response = await invalidClient.users.getCurrent(); } catch (error) { errorResponse = error; }