@@ -14,6 +14,7 @@ class RestComms extends EventEmitter {
1414 this . uri = undefined
1515 this . wsUri = undefined
1616 this . cfgPrefix = 'rest'
17+ this . uriPrefix = ''
1718 this . config = config
1819 this . sessionId = undefined
1920 this . remoteIdentity = remoteIdentity
@@ -92,7 +93,13 @@ class RestComms extends EventEmitter {
9293 this . config . write ( path , { id : this . sessionId } )
9394 }
9495
95- async call ( path , data , expectClearTextReply = false ) {
96+ async call ( path , data ,
97+ {
98+ expectClearTextReply = false ,
99+ sendClearTextRequest = false ,
100+ useSessions = true
101+ } = { }
102+ ) {
96103 if ( ! this . uri ) {
97104 await this . loadCloud ( )
98105 }
@@ -101,20 +108,33 @@ class RestComms extends EventEmitter {
101108 }
102109 await this . getServiceIdentity ( )
103110
104- const obj = { session : this . sessionId , data : data }
111+ // const obj = { session: this.sessionId, data: data }
105112
106- debug ( 'call' , path , ' req - ' , JSON . stringify ( obj ) )
113+ const fullPath = this . uri + this . uriPrefix + path
114+
107115
108- const content = await this . party . encrypt ( obj , this . remoteIdentity )
116+ let content = null
117+
118+ if ( data || this . useSessions ) {
119+ content = { data}
120+
121+ if ( useSessions ) { content . session = this . sessionId }
122+
123+ if ( ! sendClearTextRequest ) {
124+ content = await this . party . encrypt ( content , this . remoteIdentity )
125+ }
126+ }
127+
128+ debug ( 'call' , fullPath , ' req - ' , JSON . stringify ( content ) )
109129
110130 let reply
111131 try {
112- const str = await RestComms . HttpPost ( this . uri + path , content )
132+ const str = await RestComms . HttpPost ( fullPath , content )
113133 reply = JSON . parse ( str )
114134
115135 // debug('raw reply ->', reply)
116136 } catch ( error ) {
117- debug ( 'rest' , path , ' call fail ->' , error . message )
137+ debug ( 'rest' , fullPath , ' call fail ->' , error . message )
118138 throw new Error ( 'RestCommsError' )
119139 }
120140
@@ -124,13 +144,13 @@ class RestComms extends EventEmitter {
124144 expectClearTextReply
125145 )
126146
127- debug ( 'call' , path , ' res - ' , JSON . stringify ( msg , null , 2 ) )
147+ debug ( 'call' , fullPath , ' res - ' , JSON . stringify ( msg , null , 2 ) )
128148
129149 return msg
130150 }
131151
132152 async syncActors ( ) {
133- const info = await this . call ( 'api-v2- actor-info' )
153+ const info = await this . call ( 'actor-info' )
134154
135155 debug ( 'syncActors - got info' , JSON . stringify ( info , null , 2 ) )
136156
@@ -177,7 +197,7 @@ class RestComms extends EventEmitter {
177197 if ( ! this . uri ) {
178198 await this . loadCloud ( )
179199 }
180- const serverIdentity = await RestComms . HttpGet ( this . uri + 'api-v2- identity' )
200+ const serverIdentity = await RestComms . HttpGet ( this . uri + ` ${ this . uriPrefix } identity` )
181201 debug ( 'server identity - ' , serverIdentity )
182202
183203 this . remoteIdentity = dataparty_crypto . Identity . fromString ( serverIdentity )
@@ -199,7 +219,7 @@ class RestComms extends EventEmitter {
199219
200220 async redeemInvite ( code ) {
201221 // await this.party.loadIdentity()
202- return this . call ( 'api-v2- claim-user-invite' , {
222+ return this . call ( 'claim-user-invite' , {
203223 short_code : code
204224 } )
205225 }
@@ -214,7 +234,7 @@ class RestComms extends EventEmitter {
214234 return this . party
215235 . loadIdentity ( )
216236 . then ( ( ) => {
217- return this . call ( 'api-v2- oauth-github' , { code : code } )
237+ return this . call ( 'oauth-github' , { code : code } )
218238 } )
219239 . then ( sessionInfo => {
220240 debug ( sessionInfo )
@@ -280,7 +300,7 @@ class RestComms extends EventEmitter {
280300 debug ( 'actor' , this . party . actor )
281301
282302 try {
283- const reply = await this . call ( 'api-v2- rest-session' , {
303+ const reply = await this . call ( 'rest-session' , {
284304 actor : {
285305 id : this . party . actor . id ,
286306 type : this . party . actor . type
@@ -307,7 +327,7 @@ class RestComms extends EventEmitter {
307327 return this . websocketComm
308328 }
309329
310- return this . call ( 'api-v2- websocket-session' ) . then ( reply => {
330+ return this . call ( 'websocket-session' ) . then ( reply => {
311331 debug ( reply )
312332 if ( ! this . wsUri ) {
313333 this . loadCloud ( )
0 commit comments