SPB Git

Repository Public

create-app-id.js 3.6 KB 60 lines javascript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP ID & Card Vault8 * File             : scripts/portal/create-app-id.js9 * Module           : Scripts10 * Repository       : https://git.spboucher.ai/sp-id-card-vault11 * Project Website  : Not specified12 * Created          : 2026-12-0213 * Last Modified    : 2026-12-0214 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Idempotent: creates the explicit App ID ai.spboucher.idcardvault ("SP ID & Card Vault")44// with Data Protection (complete) as its only optional capability, then reads it back.45async function main(){46  const team='3YM54G49SN', ident='ai.spboucher.idcardvault', name='SP ID and Card Vault' /* the portal rejects '&' in an App ID name */;47  const get={'Content-Type':'application/vnd.api+json','Accept':'application/vnd.api+json, application/json','X-HTTP-Method-Override':'GET','X-Requested-With':'XMLHttpRequest'};48  const list=async()=>{const r=await fetch('/services-account/v1/bundleIds',{method:'POST',credentials:'include',headers:get,body:JSON.stringify({urlEncodedQueryParams:'limit=1000',teamId:team})}); const j=await r.json(); return {r,data:j.data||[]};};49  let s=await list(); let found=s.data.find(d=>d.attributes.identifier===ident);50  if(found) return JSON.stringify({ident,action:'exists',id:found.id});51  const h={'Content-Type':'application/vnd.api+json','Accept':'application/vnd.api+json, application/json','X-Requested-With':'XMLHttpRequest'};52  const c=s.r.headers.get('csrf'), ts=s.r.headers.get('csrf_ts'); if(c){h['csrf']=c; h['csrf_ts']=ts;}53  const body={data:{type:'bundleIds',attributes:{identifier:ident,name:name,seedId:team,teamId:team},relationships:{bundleIdCapabilities:{data:[54    {type:'bundleIdCapabilities',attributes:{enabled:true,settings:[{key:'DATA_PROTECTION_PERMISSION_LEVEL',options:[{key:'COMPLETE_PROTECTION'}]}]},relationships:{capability:{data:{type:'capabilities',id:'DATA_PROTECTION'}}}}]}}}};55  const r=await fetch('/services-account/v1/bundleIds',{method:'POST',credentials:'include',headers:h,body:JSON.stringify(body)});56  const t=await r.text(); let j={}; try{j=JSON.parse(t)}catch(e){}57  s=await list(); found=s.data.find(d=>d.attributes.identifier===ident);58  return JSON.stringify({ident,action:'create',status:r.status,errors:(j.errors||[]).map(e=>(e.detail||e.title)),verifiedId:found&&found.id,raw:found?undefined:t.slice(0,300)});59}60
Files main
Menu

Theme