UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.37 kB
import{a as e}from"./openclaw-state-read-record-coerce-D1s3ReAs.mjs";import{r as t}from"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import{a as n}from"./openclaw-state-read-sqlite-transaction-V1rK3HH2.mjs";import{o as r}from"./openclaw-state-read-openclaw-state-db-schema-helpers-BkqUYEFY.mjs";import{t as i}from"./openclaw-state-read-user-profile-constants-DC9CyEfK.mjs";import{d as a}from"./openclaw-state-read-user-profiles-internal-D1K1kSBE.mjs";const o=`openclaw.id`;function readOpenClawIdDisplayEmail(t){if(t===null)return null;try{let n=JSON.parse(t);return e(n)&&n.kind===`openclaw-id-display`&&typeof n.email==`string`?n.email:null}catch{return null}}function readOpenClawIdUserProfilesInDatabase(e,i){return i.length===0||!r(e,`user_profile_identities`)||!r(e,`user_profiles`)?{}:n(e,()=>{let n=a(e),r=t(e,n.selectFrom(`user_profile_identities`).select([`subject`,`profile_id`,`verified_email_json`]).where(`provider`,`=`,o).where(`subject`,`in`,[...new Set(i)])).rows;if(!r.length)return{};let s=[...new Set(r.map(e=>e.profile_id))],c=n.selectFrom(`user_profiles`),l=t(e,c.select([`id`,`display_name`,`merged_into`]).where(e=>e.or([e(`id`,`in`,s),e(`id`,`in`,c.select(`merged_into`).where(`id`,`in`,s))]))).rows,u=new Map(l.map(e=>[e.id,e]));return Object.fromEntries(r.flatMap(e=>{let t=u.get(e.profile_id),n=t?.merged_into?u.get(t.merged_into)??t:t;return n?[[e.subject,{id:n.id,displayName:n.display_name,email:readOpenClawIdDisplayEmail(e.verified_email_json)}]]:[]}))})}function readOpenClawIdLinkedProfileInDatabase(e,i){return!r(e,`user_profile_identities`)||!r(e,`user_profiles`)?null:n(e,()=>{let n=a(e),r=t(e,n.selectFrom(`user_profile_identities`).select(`profile_id`).where(`provider`,`=`,o).where(`subject`,`=`,i)).rows[0];if(!r)return null;let row=r=>t(e,n.selectFrom(`user_profiles`).select([`id`,`updated_at`,`merged_into`]).where(`id`,`=`,r)).rows[0],s=row(r.profile_id),c=s?.merged_into?row(s.merged_into):s;return c?{profileId:c.id,updatedAt:c.updated_at}:null})}function readOpenClawIdLinksOfProfileInDatabase(e,n){return r(e,`user_profile_identities`)?t(e,a(e).selectFrom(`user_profile_identities`).select([`subject`,`verified_email_json`]).where(`provider`,`=`,o).where(`profile_id`,`=`,n).orderBy(`created_at`)).rows.map(e=>({accountId:e.subject,email:readOpenClawIdDisplayEmail(e.verified_email_json)})):[]}const s={"userProfiles.openClawId.inviteCandidates":(e,n)=>({type:`userProfiles.openClawId.inviteCandidates`,profiles:!r(n,`user_profiles`)||!r(n,`user_profile_identities`)?[]:t(n,a(n).selectFrom(`user_profiles`).select([`id`,`display_name as displayName`]).where(`id`,`!=`,i).where(`merged_into`,`is`,null).where(e=>e.not(e.exists(e.selectFrom(`user_profile_identities`).select(`profile_id`).whereRef(`profile_id`,`=`,`user_profiles.id`).where(`provider`,`in`,[o,`oce.external`])))).orderBy(`display_name`).orderBy(`id`)).rows}),"userProfiles.openClawId.read":({accountIds:e},t)=>({type:`userProfiles.openClawId.read`,profiles:readOpenClawIdUserProfilesInDatabase(t,e)}),"userProfiles.openClawId.linkedProfile":({accountId:e},t)=>({type:`userProfiles.openClawId.linkedProfile`,profile:readOpenClawIdLinkedProfileInDatabase(t,e)}),"userProfiles.openClawId.linksOf":({profileId:e},t)=>({type:`userProfiles.openClawId.linksOf`,links:readOpenClawIdLinksOfProfileInDatabase(t,e)})};export{s as openClawIdUserProfileReadOperations};