@funfab/cli 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/cli/tokens.mjs +11 -6
  2. package/package.json +1 -1
package/cli/tokens.mjs CHANGED
@@ -62,7 +62,12 @@ const scopeArg=s=>s.scope==='staff'?'--staff':/^[a-z0-9]+(-[a-z0-9]+)*$/.test(s.
62
62
  const revokeCommand=i=>`funfab token revoke ${scopeArg(i.scope)} ${quote(i.name)}`
63
63
  const listCommand=i=>`funfab token list ${scopeArg(i.scope)}`
64
64
  const date=(value,time=false)=>new Intl.DateTimeFormat('en-US',{timeZone:'UTC',month:'short',day:'numeric',year:'numeric',...(time?{hour:'numeric',minute:'2-digit',hour12:true}:{})}).format(new Date(value)).replace(/\u202f/g,' ').replace(/\b(AM|PM)\b/g,m=>m.toLowerCase())
65
- const powerLabels=t=>[...(t.status?['move between Internal and Playtest']:[]),...(t.switchOff?['stop and start']:[]),...(t.access?['allow and block lists']:[])]
65
+ const formatPowers=t=>[
66
+ 'Edit and unpublish store pages',
67
+ ...(t.status?['Change the game’s status']:[]),
68
+ ...(t.switchOff?['Stop and start the game']:[]),
69
+ ...(t.access?['Requests, allow and block lists']:[])
70
+ ].join(' · ')
66
71
  const madeButNotSaved=i=>`The token "${i.name}" was made, but it couldn't be saved here,\nand it can't be shown again. Revoke it, then make a new one:\n ${revokeCommand(i)}`
67
72
  const uncertain=i=>`Couldn't tell whether the token "${i.name}" was made.\nCheck with: ${listCommand(i)}\nIf it's listed, revoke it and make a new one. Don't run create again first.`
68
73
  const failure=(code,message,command)=>Object.assign(Error(code),{display:message,nextAction:{kind:'command',command}})
@@ -146,9 +151,9 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
146
151
  const own=await read('whoami',{});if(!own)return
147
152
  const active=result.tokens.filter(activeToken)
148
153
  const rows=active.map(t=>{
149
- const powers=powerLabels(t.ticks).join(', ')
154
+ const powers=formatPowers(t.ticks)
150
155
  const age=t.lastUsedAt?Math.max(0,Math.floor((Date.now()-Date.parse(t.lastUsedAt))/60000)):null
151
- return [t.name,t.authorizerAccountId===own.accountId?'you':'a staff member',`can ${powers||'see only'}`,t.expiresAt?`ends ${date(t.expiresAt)}`:'until revoked',age===null?'never used':`last used ${age} min ago`]
156
+ return [t.name,t.authorizerAccountId===own.accountId?'you':'a staff member',`Can: ${powers}`,t.expiresAt?`ends ${date(t.expiresAt)}`:'until revoked',age===null?'never used':`last used ${age} min ago`]
152
157
  })
153
158
  const table=alignedRows(asJson?null:['Name','Created by','Permissions','Ends','Last used'],rows).split('\n')
154
159
  const powers={status:'change the status of',switchOff:'stop and start',access:'change access to'}
@@ -183,8 +188,8 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
183
188
  const mutationId=randomUUID()
184
189
  await preflight(environment,intent,mutationId)
185
190
  const operation={action:'token-create',environment,scope:intent.scope.scope,name:intent.name,ticks:intent.ticks,expiresAt:intent.expiresAt,mutationId,...(game?{game:game.gameId,revision:game.revision,affectedTitles:game.titles}:{})}
186
- const powers=powerLabels(intent.ticks)
187
- const prompt=`Create "${intent.name}" for ${scopeName}? It can ${powers.length===1&&intent.ticks.switchOff?'stop and start the game':powers.length?powers.join(', '):'see only'}. [y/N]`
191
+ const powers=formatPowers(intent.ticks)
192
+ const prompt=`Create "${intent.name}" for ${scopeName}? It can ${powers}. [y/N]`
188
193
  let response
189
194
  try {response=await approvals.write('token/create',{operation},saved,{prompt,needs:"Creating an agent token needs you to confirm it's you.",needsAction:'Creating an agent token needs your confirmation in the browser.'})}
190
195
  catch(error) {
@@ -203,7 +208,7 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
203
208
  catch {throw failure('token_delivery_lost',madeButNotSaved(intent),revokeCommand(intent))}
204
209
  const shown=displayPath(path)
205
210
  const paidLine=response.paidGameName?`\n${response.paidGameName} costs money each time it's played. Starting it and letting players in will spend money.`:''
206
- const message=`Token created: ${intent.name} (${scopeName}, ${environmentLabel(environment)})\nSaved to ${shown}\n (readable only by you; shown nowhere else)\nCan: ${powers.length?['see',...powers].join(', '):'see only'}${paidLine}\n${intent.expiresAt?`Ends: ${date(intent.expiresAt,true)} UTC`:'Lasts until revoked'}\n\nTo use it: export FUNFAB_TOKEN_FILE=${shellPath(path)}\nTo revoke: ${revokeCommand(intent)}`
211
+ const message=`Token created: ${intent.name} (${scopeName}, ${environmentLabel(environment)})\nSaved to ${shown}\n (readable only by you; shown nowhere else)\nCan: ${powers}${paidLine}\n${intent.expiresAt?`Ends: ${date(intent.expiresAt,true)} UTC`:'Lasts until revoked'}\n\nTo use it: export FUNFAB_TOKEN_FILE=${shellPath(path)}\nTo revoke: ${revokeCommand(intent)}`
207
212
  output({environment,name:intent.name,path,message})
208
213
  if(intent.print)process.stdout.write(response.tokenValue+'\n')
209
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funfab/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22"