UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 5.04 kB
import e from"../db/query-builder/index.mjs";import t from"./parents/static-repository.mjs";import n from"zod";import{sql as r}from"kysely";var i=class extends t{constructor(e,t){super(e,t,`lucid_client_integrations`)}tableSchema=n.object({id:n.number(),name:n.string(),description:n.string().nullable(),enabled:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),scopes:n.array(n.object({scope:n.string()})).optional(),key:n.string(),api_key:n.string(),secret:n.string(),tenant_key:n.string().nullable(),last_used_at:n.union([n.string(),n.date()]).nullable(),last_used_ip:n.string().nullable(),last_used_user_agent:n.string().nullable(),created_at:n.union([n.string(),n.date()]).nullable(),updated_at:n.union([n.string(),n.date()]).nullable()});columnFormats={id:this.dbAdapter.getDataType(`primary`),name:this.dbAdapter.getDataType(`text`),description:this.dbAdapter.getDataType(`text`),enabled:this.dbAdapter.getDataType(`boolean`),key:this.dbAdapter.getDataType(`text`),api_key:this.dbAdapter.getDataType(`text`),secret:this.dbAdapter.getDataType(`text`),tenant_key:this.dbAdapter.getDataType(`text`),last_used_at:this.dbAdapter.getDataType(`timestamp`),last_used_ip:this.dbAdapter.getDataType(`varchar`,255),last_used_user_agent:this.dbAdapter.getDataType(`text`),created_at:this.dbAdapter.getDataType(`timestamp`),updated_at:this.dbAdapter.getDataType(`timestamp`)};queryConfig={tableKeys:{filters:{key:`key`,name:`name`,description:`description`,enabled:`enabled`,lastUsedAt:`last_used_at`,lastUsedIp:`last_used_ip`,createdAt:`created_at`,updatedAt:`updated_at`},sorts:{name:`name`,description:`description`,enabled:`enabled`,createdAt:`created_at`,updatedAt:`updated_at`}},operators:{name:`contains`,description:`contains`}};async selectSingleByIdWithScopes(t){let n=this.db.selectFrom(`lucid_client_integrations`).select(e=>[`id`,`key`,`name`,`description`,`enabled`,`tenant_key`,`last_used_at`,`last_used_ip`,`last_used_user_agent`,`created_at`,`updated_at`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_client_integration_scopes`).select([`scope`]).whereRef(`lucid_client_integration_scopes.client_integration_id`,`=`,`lucid_client_integrations.id`)).as(`scopes`)]).where(`id`,`=`,t.id).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_client_integrations.tenant_key`})),r=await this.executeQuery(()=>n.executeTakeFirst(),{method:`selectSingleByIdWithScopes`});return r.response.error?r.response:this.validateResponse(r,{...t.validation,mode:`single`,select:[`id`,`key`,`name`,`description`,`enabled`,`tenant_key`,`last_used_at`,`last_used_ip`,`last_used_user_agent`,`created_at`,`updated_at`,`scopes`]})}async selectSingleByKeyWithScopes(e){let t=this.db.selectFrom(`lucid_client_integrations`).select(e=>[`id`,`key`,`api_key`,`secret`,`enabled`,`tenant_key`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_client_integration_scopes`).select([`scope`]).whereRef(`lucid_client_integration_scopes.client_integration_id`,`=`,`lucid_client_integrations.id`)).as(`scopes`)]).where(`key`,`=`,e.key),n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`selectSingleByKeyWithScopes`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`single`,select:[`id`,`key`,`api_key`,`secret`,`enabled`,`scopes`]})}async selectMultipleFilteredWithScopes(t){let n=await this.executeQuery(async()=>{let n=this.db.selectFrom(`lucid_client_integrations`).select(e=>[`id`,`key`,`name`,`description`,`enabled`,`tenant_key`,`last_used_at`,`last_used_ip`,`last_used_user_agent`,`created_at`,`updated_at`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_client_integration_scopes`).select([`scope`]).whereRef(`lucid_client_integration_scopes.client_integration_id`,`=`,`lucid_client_integrations.id`)).as(`scopes`)]).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_client_integrations.tenant_key`})),i=this.db.selectFrom(`lucid_client_integrations`).select(r`count(*)`.as(`count`)).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_client_integrations.tenant_key`})),{main:a,count:o}=e.main({main:n,count:i},{queryParams:t.queryParams,database:this.dbAdapter.config,meta:{...this.queryConfig,customFilters:{scope:({eb:e,filter:t})=>{let n=Array.isArray(t.value)?t.value:[t.value];return e.exists(e.selectFrom(`lucid_client_integration_scopes`).select(`lucid_client_integration_scopes.id`).whereRef(`lucid_client_integration_scopes.client_integration_id`,`=`,`lucid_client_integrations.id`).where(`lucid_client_integration_scopes.scope`,`in`,n.map(String)))}}}}),[s,c]=await Promise.all([a.execute(),o?.executeTakeFirst()]);return[s,c]},{method:`selectMultipleFilteredWithScopes`});return n.response.error?n.response:this.validateResponse(n,{...t.validation,mode:`multiple-count`,select:[`id`,`key`,`name`,`description`,`enabled`,`tenant_key`,`last_used_at`,`last_used_ip`,`last_used_user_agent`,`created_at`,`updated_at`,`scopes`]})}};export{i as default}; //# sourceMappingURL=client-integrations.mjs.map