-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathconfig.ts
More file actions
61 lines (56 loc) · 2.56 KB
/
Copy pathconfig.ts
File metadata and controls
61 lines (56 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { readFileSync } from 'node:fs';
import { join } from 'pathe';
import yaml from 'js-yaml';
import envPaths from 'env-paths';
import info from '../../package.json' with { type: 'json' };
const paths = envPaths('cosmo', { suffix: '' });
export const configDir = paths.config;
export const dataDir = paths.data;
export const cacheDir = paths.cache;
export const configFile = join(configDir, 'config.yaml');
export const getLoginDetails = (): { accessToken: string; organizationSlug: string } | null => {
try {
const data = yaml.load(readFileSync(configFile, 'utf8'));
const loginData = JSON.parse(JSON.stringify(data));
return { accessToken: loginData.accessToken, organizationSlug: loginData.organizationSlug };
} catch {
return null;
}
};
export const config = {
version: info.version,
baseURL: process.env.COSMO_API_URL || 'https://cosmo-cp.wundergraph.com',
// environment var first to allow overriding
apiKey: process.env.COSMO_API_KEY,
kcApiURL: process.env.KC_API_URL || 'https://accounts.wundergraph.com/auth',
webURL: process.env.COSMO_WEB_URL || 'https://cosmo.wundergraph.com',
kcClientId: process.env.KC_CLIENT_ID || 'cosmo-cli',
kcRealm: process.env.KC_REALM || 'cosmo',
cdnURL: process.env.CDN_URL || 'https://cosmo-cdn.wundergraph.com',
disableUpdateCheck: process.env.DISABLE_UPDATE_CHECK || 'false',
checkAuthor: process.env.COSMO_VCS_AUTHOR || '',
checkCommitSha: process.env.COSMO_VCS_COMMIT || '',
checkBranch: process.env.COSMO_VCS_BRANCH || '',
pluginRegistryURL: process.env.PLUGIN_REGISTRY_URL || 'cosmo-registry.wundergraph.com',
pluginRegistryInsecure: process.env.PLUGIN_REGISTRY_INSECURE === 'true',
demoLabelMatcher: 'graph=demo' as const,
demoGraphName: 'demo' as const,
demoNamespace: 'default' as const,
demoOnboardingRepositoryName: 'wundergraph/cosmo-onboarding' as const,
demoOnboardingRepositoryBranch: 'main' as const,
dockerBuilderName: 'cosmo-builder' as const,
defaultTelemetryEndpoint: process.env.DEFAULT_TELEMETRY_ENDPOINT,
graphqlMetricsCollectorEndpoint: process.env.GRAPHQL_METRICS_COLLECTOR_ENDPOINT,
demoRouterPort: 3002 as const,
demoPluginNames: ['products', 'reviews'] as const,
demoRouterTokenName: 'demo-router-token' as const,
demoRouterImage: 'ghcr.io/wundergraph/cosmo/router:latest' as const,
demoRouterContainerName: 'cosmo-demo-router' as const,
};
export const getBaseHeaders = (): HeadersInit => {
return {
'user-agent': `cosmo-cli/${info.version}`,
authorization: 'Bearer ' + config.apiKey,
'cosmo-org-slug': getLoginDetails()?.organizationSlug || '',
};
};