/** * Executor and config store for CLI * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ import { createConfigStore } from 'appstash'; import { createClient } from '../orm'; const store = createConfigStore('csdk', { stashName: 'constructive', }); export const getStore = () => store; export function getClient(contextName?: string) { let ctx = null; if (contextName) { ctx = store.loadContext(contextName); if (!ctx) { throw new Error(`Context "${contextName}" not found.`); } } else { ctx = store.getCurrentContext(); if (!ctx) { throw new Error('No active context. Run "context create" or "context use" first.'); } } const headers: Record = {}; if (store.hasValidCredentials(ctx.name)) { const creds = store.getCredentials(ctx.name); if (creds?.token) { headers.Authorization = `Bearer ${creds.token}`; } } return createClient({ endpoint: ctx.endpoint, headers: headers, }); }