legacy-appointment-deletions.mjs 1.1 KB

1234567891011121314
  1. import {readFileSync} from 'node:fs';
  2. import {withXiaoshuRuntime} from './xiaoshu-runtime-compat.mjs';
  3. export function buildAppointmentDeletionGateway(company,windows=[]){
  4. const read=name=>readFileSync(new URL('../cloud/'+name+'.js',import.meta.url),'utf8');
  5. const code=(read('legacy-writing-sync-ownership')+'\n'+read('legacy-appointment-deletions')).replaceAll('__COMPANY_ID__',JSON.stringify(company)).replaceAll('__WINDOWS__',JSON.stringify(windows));
  6. const source=withXiaoshuRuntime(code);
  7. new Function(source);return source;
  8. }
  9. export function patchAppointmentDeletionCapability(code){
  10. if(code.includes("appointmentDeletionVersion:'confirmed-ids-v1'"))return code;
  11. const handler=code.indexOf('async function handler(request,response)'),at=code.indexOf(" if(p.action===",handler);
  12. if(handler<0||at<handler)throw Error('Unknown direct sync handler');
  13. return code.slice(0,at)+" if(p.action==='status'){const result=await directControl(p,co,u);return response.json({success:true,data:{...result,appointmentDeletionVersion:'confirmed-ids-v1'}});}\n"+code.slice(at);
  14. }