@funfab/cli 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/funfab.mjs +5 -1
- package/package.json +1 -1
package/cli/funfab.mjs
CHANGED
|
@@ -141,7 +141,11 @@ const load=async()=>{
|
|
|
141
141
|
async function call(path,body,ticket,signal,origin=api) {
|
|
142
142
|
const actionConfirmation=path==='token/create'||path==='game/action'&&body?.operation?.action==='unhold'
|
|
143
143
|
const response=await fetch(`${origin}/api/cli/${path}`,{redirect:'error',method:body===undefined?'GET':'POST',headers:{...(body===undefined?{}:{'Content-Type':'application/json'}),...(actionConfirmation?{'FunFab-CLI-Action-Confirmation':'1'}:{}),...(ticket?{Authorization:`Bearer ${ticket}`}:{})},...(body===undefined?{}:{body:JSON.stringify(body)}),signal:signal?AbortSignal.any([signal,AbortSignal.timeout(10000)]):AbortSignal.timeout(path==='submit'?180000:10000)})
|
|
144
|
-
const
|
|
144
|
+
const rateLimited=response.status===429
|
|
145
|
+
const data=await (rateLimited?response.json().catch(()=>null):response.json())
|
|
146
|
+
if(rateLimited&&(typeof data?.error!=='string'||!data.error.trim())) {
|
|
147
|
+
throw problem('rate_limited','Too many requests to FunFab right now. Wait a minute, then try again.',person('Wait a minute, then try again.'))
|
|
148
|
+
}
|
|
145
149
|
if(data?.status==='action_confirmation_needed'&&(!actionConfirmation||response.status!==202))return malformedConfirmation()
|
|
146
150
|
if(actionConfirmation&&response.status===202&&!writePauseStatuses.includes(data?.status))return malformedConfirmation()
|
|
147
151
|
if(!response.ok) throw Object.assign(Error(data.error??'account_unavailable'),(path.startsWith('game/')||path.startsWith('token/')||path==='confirm-request')&&['game_request_invalid','game_request_conflict'].includes(data.error)&&['input_invalid','cursor_invalid','expiry_elapsed','consumed','answered','invalidated'].includes(data.reason)?{reason:data.reason}:{});return data
|