@funfab/cli 0.3.1 → 0.3.2
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/tokens.mjs +17 -18
- package/package.json +1 -1
package/cli/tokens.mjs
CHANGED
|
@@ -118,7 +118,7 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
|
|
|
118
118
|
if(value.status==='activation_needed') {if(!await approvals.wait(saved.ticket,value,{activation:true}))return null;value=await call(path,input,saved.ticket)}
|
|
119
119
|
return value
|
|
120
120
|
}
|
|
121
|
-
let environment,scopeName,game
|
|
121
|
+
let environment,scopeName,game,tokenToRevoke
|
|
122
122
|
if(intent.action==='revoke'&&!intent.allForGame) {
|
|
123
123
|
let listed
|
|
124
124
|
try {listed=await read('token/list',{scope:intent.scope})}
|
|
@@ -126,9 +126,9 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
|
|
|
126
126
|
if(!listed)return
|
|
127
127
|
const matches=listed.tokens.filter(t=>t.name===intent.name),current=matches.filter(t=>!t.revokedAt)
|
|
128
128
|
if(!current.length&&matches.some(t=>t.revokedAt)) {output({environment:listed.environment,revokedCount:0,message:"Revoked. The agent can't use it any more."});return}
|
|
129
|
-
if(current.length!==1)throw failure('game_permission_denied',`No token named "${intent.name}" that you can revoke.`,listCommand(intent))
|
|
130
|
-
|
|
131
|
-
} else if(intent.scope?.scope==='staff'||intent.action==='kill-switch'||intent.action==='list'
|
|
129
|
+
if(current.length!==1||!current[0].id)throw failure('game_permission_denied',`No token named "${intent.name}" that you can revoke.`,listCommand(intent))
|
|
130
|
+
tokenToRevoke=current[0];scopeName=tokenToRevoke.gameId??intent.scope.game
|
|
131
|
+
} else if(intent.scope?.scope==='staff'||intent.action==='kill-switch'||intent.action==='list') {
|
|
132
132
|
const result=await read('token/list',intent.scope?{scope:intent.scope}:{});if(!result)return
|
|
133
133
|
environment=result.environment;scopeName='staff, every game you manage'
|
|
134
134
|
if(intent.action==='list')return list(result)
|
|
@@ -153,25 +153,24 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
|
|
|
153
153
|
])]
|
|
154
154
|
output({environment:result.environment,tokens:result.tokens,message:lines.join('\n')||(!asJson?'No tokens.':'')})
|
|
155
155
|
}
|
|
156
|
-
if(intent.
|
|
156
|
+
if(intent.allForGame) {
|
|
157
|
+
if(!game.gameId||!game.name)throw Error('account_unavailable')
|
|
158
|
+
const prompt=`Revoke every game token for ${game.name} (${game.gameId})? Any agent using one stops working at once. [y/N]`
|
|
159
|
+
const result=await approvals.write('token/revoke',{game:game.gameId,allForGame:true,reason:intent.reason},saved,{prompt})
|
|
160
|
+
if(result)output({...result,message:`Revoked ${result.revokedCount} tokens for ${game.name}. Agents can't use them any more.\nStaff tokens still work here. To stop those too: funfab token kill-switch on`})
|
|
161
|
+
return
|
|
162
|
+
}
|
|
157
163
|
if(intent.action!=='create') {
|
|
158
|
-
const {action
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
const listed=await read('token/list',{scope:{scope:'game',game:intent.game}});if(!listed)return
|
|
162
|
-
const tokens=listed.tokens.filter(activeToken)
|
|
163
|
-
if(!tokens.length){output({environment,revokedCount:0,message:'No tokens.'});return}
|
|
164
|
-
for(const token of tokens)if(!await approvals.question(`Revoke \"${token.name}\" for ${game.name}? Any agent using it stops working at once. [y/N]`))return
|
|
165
|
-
const result=await call('token/revoke',{...input,approvedIn:approvals.approvedIn},saved.ticket)
|
|
166
|
-
output({...result,message:`Revoked ${result.revokedCount} tokens for ${game.name}. Agents can't use them any more.`});return
|
|
167
|
-
}
|
|
164
|
+
const {action,reason}=intent
|
|
165
|
+
const input=action==='kill-switch'?{state:'on',reason}:{tokenId:tokenToRevoke.id,...(reason?{reason}:{})}
|
|
166
|
+
const prompt=action==='kill-switch'?`Switch off every agent token on ${environmentLabel(environment)}? All agents stop at once, until staff switch tokens back on. [y/N]`:intent.scope.scope==='staff'?`Revoke staff token "${tokenToRevoke.name}"? Any agent using it stops working at once. [y/N]`:`Revoke "${tokenToRevoke.name}" for ${scopeName}? Any agent using it stops working at once. [y/N]`
|
|
168
167
|
let result
|
|
169
|
-
try {result=await approvals.write(`token/${action}`,
|
|
168
|
+
try {result=await approvals.write(`token/${action}`,input,saved,{prompt})}
|
|
170
169
|
catch(error) {
|
|
171
|
-
if(action==='revoke'
|
|
170
|
+
if(action==='revoke'&&error.message==='game_permission_denied')throw failure(error.message,`No token named "${intent.name}" that you can revoke.`,listCommand(intent))
|
|
172
171
|
throw error
|
|
173
172
|
}
|
|
174
|
-
if(result)output({...result,message:action==='kill-switch'?`All agent tokens on ${environmentLabel(result.environment)} are switched off. People can still list and revoke them.`:
|
|
173
|
+
if(result)output({...result,message:action==='kill-switch'?`All agent tokens on ${environmentLabel(result.environment)} are switched off. People can still list and revoke them.`:"Revoked. The agent can't use it any more."})
|
|
175
174
|
return
|
|
176
175
|
}
|
|
177
176
|
if(!asJson)output({message:`${environmentLabel(environment)} · ${scopeName}`})
|