File tree 4 files changed +48
-0
lines changed
4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ declare module "replicate" {
8
8
response : Response ;
9
9
}
10
10
11
+ export interface Account {
12
+ type : "user" | "organization" ;
13
+ username : string ;
14
+ name : string ;
15
+ github_url ?: string ;
16
+ }
17
+
11
18
export interface Collection {
12
19
name : string ;
13
20
slug : string ;
@@ -140,6 +147,10 @@ declare module "replicate" {
140
147
stop ?: ( prediction : Prediction ) => Promise < boolean >
141
148
) : Promise < Prediction > ;
142
149
150
+ accounts : {
151
+ current ( ) : Promise < Account > ;
152
+ } ;
153
+
143
154
collections : {
144
155
list ( ) : Promise < Page < Collection > > ;
145
156
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");
3
3
const { Stream } = require ( "./lib/stream" ) ;
4
4
const { withAutomaticRetries } = require ( "./lib/util" ) ;
5
5
6
+ const accounts = require ( "./lib/accounts" ) ;
6
7
const collections = require ( "./lib/collections" ) ;
7
8
const deployments = require ( "./lib/deployments" ) ;
8
9
const hardware = require ( "./lib/hardware" ) ;
@@ -47,6 +48,10 @@ class Replicate {
47
48
this . baseUrl = options . baseUrl || "https://api.replicate.com/v1" ;
48
49
this . fetch = options . fetch || globalThis . fetch ;
49
50
51
+ this . accounts = {
52
+ current : accounts . current . bind ( this ) ,
53
+ } ;
54
+
50
55
this . collections = {
51
56
list : collections . list . bind ( this ) ,
52
57
get : collections . get . bind ( this ) ,
Original file line number Diff line number Diff line change @@ -67,6 +67,22 @@ describe("Replicate client", () => {
67
67
} ) ;
68
68
} ) ;
69
69
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
+
70
86
describe ( "collections.list" , ( ) => {
71
87
test ( "Calls the correct API route" , async ( ) => {
72
88
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