@@ -22,7 +22,7 @@ const AUTO_REFRESH_PREFETCH_TIME = 5000;
2222
2323const ACL_TOKEN_HEADER = "X-Dgraph-AccessToken" ;
2424const ALPHA_AUTH_TOKEN_HEADER = "X-Dgraph-AuthToken" ;
25- const SLASH_API_KEY_HEADER = "X-Auth-Token" ;
25+ const DGRAPHCLOUD_API_KEY_HEADER = "X-Auth-Token" ;
2626
2727/**
2828 * Stub is a stub/client connecting to a single dgraph server instance.
@@ -302,56 +302,56 @@ export class DgraphClientStub {
302302 }
303303
304304 public abort ( ctx : TxnContext ) : Promise < TxnContext > {
305- let url = ! this . legacyApi
305+ let url = ! this . legacyApi
306306 ? `commit?startTs=${ ctx . start_ts } &abort=true`
307307 : `abort/${ ctx . start_ts } ` ;
308308
309- if ( ctx ?. hash ?. length > 0 ) {
310- if ( ! this . legacyApi ) {
309+ if ( ctx ?. hash ?. length > 0 ) {
310+ if ( ! this . legacyApi ) {
311311 url += `&hash=${ ctx . hash } ` ;
312- }
313- }
312+ }
313+ }
314314
315- return this . callAPI ( url , { ...this . options , method : "POST" } ) ;
315+ return this . callAPI ( url , { ...this . options , method : "POST" } ) ;
316316 }
317317
318318 public async login (
319319 userid ?: string ,
320320 password ?: string ,
321321 refreshToken ?: string ,
322322 ) : Promise < boolean > {
323- if ( this . legacyApi ) {
324- throw new Error ( "Pre v1.1 clients do not support Login methods" ) ;
325- }
326-
327- const body : { [ k : string ] : string } = { } ;
328- if (
329- userid === undefined &&
330- refreshToken === undefined &&
331- this . refreshToken === undefined
332- ) {
333- throw new Error (
334- "Cannot find login details: neither userid/password nor refresh token are specified" ,
335- ) ;
336- }
337- if ( userid === undefined ) {
338- body . refresh_token =
339- refreshToken !== undefined ? refreshToken : this . refreshToken ;
340- } else {
341- body . userid = userid ;
342- body . password = password ;
343- }
344-
345- const res : LoginResponse = await this . callAPI ( "login" , {
346- ...this . options ,
347- method : "POST" ,
348- body : JSON . stringify ( body ) ,
349- } ) ;
350- this . accessToken = res . data . accessJWT ;
351- this . refreshToken = res . data . refreshJWT ;
352-
353- this . maybeStartRefreshTimer ( this . accessToken ) ;
354- return true ;
323+ if ( this . legacyApi ) {
324+ throw new Error ( "Pre v1.1 clients do not support Login methods" ) ;
325+ }
326+
327+ const body : { [ k : string ] : string } = { } ;
328+ if (
329+ userid === undefined &&
330+ refreshToken === undefined &&
331+ this . refreshToken === undefined
332+ ) {
333+ throw new Error (
334+ "Cannot find login details: neither userid/password nor refresh token are specified" ,
335+ ) ;
336+ }
337+ if ( userid === undefined ) {
338+ body . refresh_token =
339+ refreshToken !== undefined ? refreshToken : this . refreshToken ;
340+ } else {
341+ body . userid = userid ;
342+ body . password = password ;
343+ }
344+
345+ const res : LoginResponse = await this . callAPI ( "login" , {
346+ ...this . options ,
347+ method : "POST" ,
348+ body : JSON . stringify ( body ) ,
349+ } ) ;
350+ this . accessToken = res . data . accessJWT ;
351+ this . refreshToken = res . data . refreshJWT ;
352+
353+ this . maybeStartRefreshTimer ( this . accessToken ) ;
354+ return true ;
355355 }
356356
357357 public async loginIntoNamespace (
@@ -444,15 +444,19 @@ export class DgraphClientStub {
444444 }
445445
446446 /**
447- * @deprecated since v21.3 and will be removed in v21.07 release. For more details, see:
448- * https://discuss.dgraph.io/t/regarding-slash-cloud-dgraph-endpoints-in-the-clients/13492
447+ * @deprecated since v21.3 and will be removed in v21.07 release.
448+ * Please use { @link setCloudApiKey} instead.
449449 */
450450
451451 public setSlashApiKey ( apiKey : string ) {
452+ this . setCloudApiKey ( apiKey ) ;
453+ }
454+
455+ public setCloudApiKey ( apiKey : string ) {
452456 if ( this . options . headers === undefined ) {
453457 this . options . headers = { } ;
454458 }
455- this . options . headers [ SLASH_API_KEY_HEADER ] = apiKey ;
459+ this . options . headers [ DGRAPHCLOUD_API_KEY_HEADER ] = apiKey ;
456460 }
457461
458462 private cancelRefreshTimer ( ) {
0 commit comments