File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ declare module "replicate" {
88 response : Response ;
99 }
1010
11+ export interface Account {
12+ type : "user" | "organization" ;
13+ username : string ;
14+ name : string ;
15+ github_url ?: string ;
16+ }
17+
1118 export interface Collection {
1219 name : string ;
1320 slug : string ;
@@ -140,6 +147,10 @@ declare module "replicate" {
140147 stop ?: ( prediction : Prediction ) => Promise < boolean >
141148 ) : Promise < Prediction > ;
142149
150+ accounts : {
151+ current ( ) : Promise < Account > ;
152+ } ;
153+
143154 collections : {
144155 list ( ) : Promise < Page < Collection > > ;
145156 get ( collection_slug : string ) : Promise < Collection > ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const ModelVersionIdentifier = require("./lib/identifier");
33const { Stream } = require ( "./lib/stream" ) ;
44const { withAutomaticRetries } = require ( "./lib/util" ) ;
55
6+ const accounts = require ( "./lib/accounts" ) ;
67const collections = require ( "./lib/collections" ) ;
78const deployments = require ( "./lib/deployments" ) ;
89const hardware = require ( "./lib/hardware" ) ;
@@ -47,6 +48,10 @@ class Replicate {
4748 this . baseUrl = options . baseUrl || "https://api.replicate.com/v1" ;
4849 this . fetch = options . fetch || globalThis . fetch ;
4950
51+ this . accounts = {
52+ current : accounts . current . bind ( this ) ,
53+ } ;
54+
5055 this . collections = {
5156 list : collections . list . bind ( this ) ,
5257 get : collections . get . bind ( this ) ,
Original file line number Diff line number Diff line change @@ -67,6 +67,22 @@ describe("Replicate client", () => {
6767 } ) ;
6868 } ) ;
6969
70+ describe ( "accounts.current" , ( ) => {
71+ test ( "Calls the correct API route" , async ( ) => {
72+ nock ( BASE_URL ) . get ( "/account" ) . reply ( 200 , {
73+ type : "organization" ,
74+ username : "replicate" ,
75+ name : "Replicate" ,
76+ github_url : "https://github.com/replicate" ,
77+ } ) ;
78+
79+ const account = await client . accounts . current ( ) ;
80+ expect ( account . type ) . toBe ( "organization" ) ;
81+ expect ( account . username ) . toBe ( "replicate" ) ;
82+ } ) ;
83+ // Add more tests for error handling, edge cases, etc.
84+ } ) ;
85+
7086 describe ( "collections.list" , ( ) => {
7187 test ( "Calls the correct API route" , async ( ) => {
7288 nock ( BASE_URL )
Original file line number Diff line number Diff line change 1+ /**
2+ * Get the current account
3+ *
4+ * @returns {Promise<object> } Resolves with the current account
5+ */
6+ async function getCurrentAccount ( ) {
7+ const response = await this . request ( "/account" , {
8+ method : "GET" ,
9+ } ) ;
10+
11+ return response . json ( ) ;
12+ }
13+
14+ module . exports = {
15+ current : getCurrentAccount ,
16+ } ;
You can’t perform that action at this time.
0 commit comments