feat(sdk): use config file as single source of truth, remove env var fallbacks (#19409)
## Summary - **Config as source of truth**: `~/.twenty/config.json` is now the single source of truth for SDK authentication — env var fallbacks have been removed from the config resolution chain. - **Test instance support**: `twenty server start --test` spins up a dedicated Docker instance on port 2021 with its own config (`config.test.json`), so integration tests don't interfere with the dev environment. - **API key auth for marketplace**: Removed `UserAuthGuard` from `MarketplaceResolver` so API key tokens (workspace-scoped) can call `installMarketplaceApp`. - **CI for example apps**: Added monorepo CI workflows for `hello-world` and `postcard` example apps to catch regressions. - **Simplified CI**: All `ci-create-app-e2e` and example app workflows now use a shared `spawn-twenty-app-dev-test` action (Docker-based) instead of building the server from source. Consolidated auth env vars to `TWENTY_API_URL` + `TWENTY_API_KEY`. - **Template publishing fix**: `create-twenty-app` template now correctly preserves `.github/` and `.gitignore` through npm publish (stored without leading dot, renamed after copy). ## Test plan - [x] CI SDK (lint, typecheck, unit, integration, e2e) — all green - [x] CI Example App Hello World — green - [x] CI Example App Postcard — green - [x] CI Create App E2E minimal — green - [x] CI Front, CI Server, CI Shared — green
This commit is contained in:
@@ -145,12 +145,6 @@ export class ApiClient {
|
||||
return this.tokenOverride;
|
||||
}
|
||||
|
||||
const envToken = process.env.TWENTY_TOKEN;
|
||||
|
||||
if (envToken) {
|
||||
return envToken;
|
||||
}
|
||||
|
||||
const config = await this.configService.getConfig();
|
||||
const accessToken = config.accessToken;
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ export class ConfigService {
|
||||
private readonly configPath: string;
|
||||
private static activeRemote = DEFAULT_REMOTE_NAME;
|
||||
|
||||
constructor() {
|
||||
this.configPath = getConfigPath();
|
||||
constructor(options?: { configPath?: string }) {
|
||||
this.configPath = options?.configPath ?? getConfigPath();
|
||||
}
|
||||
|
||||
static setActiveRemote(name?: string) {
|
||||
@@ -127,13 +127,6 @@ export class ConfigService {
|
||||
}
|
||||
|
||||
async getConfig(): Promise<RemoteConfig> {
|
||||
if (process.env.TWENTY_TOKEN && process.env.TWENTY_API_URL) {
|
||||
return {
|
||||
apiUrl: process.env.TWENTY_API_URL,
|
||||
accessToken: process.env.TWENTY_TOKEN,
|
||||
};
|
||||
}
|
||||
|
||||
return this.getConfigForRemote(this.getActiveRemoteName());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
const TEST_CONFIG_DIR = path.join(os.tmpdir(), '.twenty-sdk-test');
|
||||
const TWENTY_DIR = path.join(os.homedir(), '.twenty');
|
||||
|
||||
export const getConfigPath = (): string => {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return path.join(TEST_CONFIG_DIR, 'config.json');
|
||||
export const getConfigPath = (test = false): string => {
|
||||
if (test || process.env.NODE_ENV === 'test') {
|
||||
return path.join(TWENTY_DIR, 'config.test.json');
|
||||
}
|
||||
|
||||
return path.join(os.homedir(), '.twenty', 'config.json');
|
||||
return path.join(TWENTY_DIR, 'config.json');
|
||||
};
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
export const CONTAINER_NAME = 'twenty-app-dev';
|
||||
export const TEST_CONTAINER_NAME = 'twenty-app-dev-test';
|
||||
export const IMAGE = 'twentycrm/twenty-app-dev:latest';
|
||||
export const DEFAULT_PORT = 2020;
|
||||
export const DEFAULT_TEST_PORT = 2021;
|
||||
|
||||
export const isContainerRunning = (): boolean => {
|
||||
export const isContainerRunning = (containerName = CONTAINER_NAME): boolean => {
|
||||
try {
|
||||
const result = execSync(
|
||||
`docker inspect -f '{{.State.Running}}' ${CONTAINER_NAME}`,
|
||||
`docker inspect -f '{{.State.Running}}' ${containerName}`,
|
||||
{ encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] },
|
||||
).trim();
|
||||
|
||||
@@ -17,24 +19,27 @@ export const isContainerRunning = (): boolean => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getContainerPort = (): number => {
|
||||
export const getContainerPort = (containerName = CONTAINER_NAME): number => {
|
||||
const defaultPort =
|
||||
containerName === TEST_CONTAINER_NAME ? DEFAULT_TEST_PORT : DEFAULT_PORT;
|
||||
|
||||
try {
|
||||
const result = execSync(
|
||||
`docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' ${CONTAINER_NAME}`,
|
||||
`docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' ${containerName}`,
|
||||
{ encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] },
|
||||
);
|
||||
|
||||
const match = result.match(/^NODE_PORT=(\d+)$/m);
|
||||
|
||||
return match ? parseInt(match[1], 10) : DEFAULT_PORT;
|
||||
return match ? parseInt(match[1], 10) : defaultPort;
|
||||
} catch {
|
||||
return DEFAULT_PORT;
|
||||
return defaultPort;
|
||||
}
|
||||
};
|
||||
|
||||
export const containerExists = (): boolean => {
|
||||
export const containerExists = (containerName = CONTAINER_NAME): boolean => {
|
||||
try {
|
||||
execSync(`docker inspect ${CONTAINER_NAME}`, {
|
||||
execSync(`docker inspect ${containerName}`, {
|
||||
stdio: ['pipe', 'pipe', 'ignore'],
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user