farseer-cli 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/commands/config.js +12 -6
- package/dist/commands/config.js.map +2 -2
- package/dist/commands/pull.js +5 -2
- package/dist/commands/pull.js.map +2 -2
- package/dist/commands/push.js +17 -4
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/status.js +18 -4
- package/dist/commands/status.js.map +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools/syncTools.js +131 -39
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/services/farseerFactory.js +15 -0
- package/dist/services/farseerFactory.js.map +2 -2
- package/dist/services/syncService.js +137 -8
- package/dist/services/syncService.js.map +2 -2
- package/dist/utils/cliOptions.js +7 -2
- package/dist/utils/cliOptions.js.map +2 -2
- package/dist/utils/fileValidation.js +3 -2
- package/dist/utils/fileValidation.js.map +2 -2
- package/dist/utils/helpers.js +23 -2
- package/dist/utils/helpers.js.map +2 -2
- package/dist/utils/syncReporting.js +66 -0
- package/dist/utils/syncReporting.js.map +7 -0
- package/docs/cli-guide.md +2 -2
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var farseerFactory_exports = {};
|
|
30
30
|
__export(farseerFactory_exports, {
|
|
31
31
|
DEFAULT_SCRIPT_EXTENSIONS: () => DEFAULT_SCRIPT_EXTENSIONS,
|
|
32
|
+
DEFAULT_SYNC_EXTENSIONS: () => DEFAULT_SYNC_EXTENSIONS,
|
|
32
33
|
ensureFreshToken: () => ensureFreshToken,
|
|
33
34
|
getAvailableAuth: () => getAvailableAuth,
|
|
34
35
|
getFarseerClient: () => getFarseerClient,
|
|
@@ -60,6 +61,19 @@ function showLoginPrompt(tenant) {
|
|
|
60
61
|
import_logger.logger.dim('Or use "farseer config set <tenant> --api-key <key>" for API key auth.');
|
|
61
62
|
}
|
|
62
63
|
const DEFAULT_SCRIPT_EXTENSIONS = [".ts", ".js"];
|
|
64
|
+
const DEFAULT_SYNC_EXTENSIONS = [
|
|
65
|
+
// Code (frontend / scripts)
|
|
66
|
+
".ts",
|
|
67
|
+
".js",
|
|
68
|
+
// Code (Python)
|
|
69
|
+
".py",
|
|
70
|
+
// Config / data
|
|
71
|
+
".yml",
|
|
72
|
+
".yaml",
|
|
73
|
+
".json",
|
|
74
|
+
// Docs
|
|
75
|
+
".md"
|
|
76
|
+
];
|
|
63
77
|
async function getFarseerClient(organisation, tenant) {
|
|
64
78
|
const auth = (0, import_configService.getUserAuth)();
|
|
65
79
|
if (auth) {
|
|
@@ -221,6 +235,7 @@ async function getNativeFarseerClient(organisation, tenant) {
|
|
|
221
235
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
236
|
0 && (module.exports = {
|
|
223
237
|
DEFAULT_SCRIPT_EXTENSIONS,
|
|
238
|
+
DEFAULT_SYNC_EXTENSIONS,
|
|
224
239
|
ensureFreshToken,
|
|
225
240
|
getAvailableAuth,
|
|
226
241
|
getFarseerClient,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/services/farseerFactory.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Factory for creating Farseer API client based on available authentication\n *\n * Priority:\n * 1. JWT token (from browser login) - try first\n * 2. API key (from config) - fallback if JWT fails or unavailable\n * 3. Prompt user to login - if nothing works\n */\n\nimport * as farseer from 'farseer-client';\nimport { FarseerService } from './farseerService';\nimport { FarseerApi } from './farseerApi';\nimport { getCredential, getUserAuth, isUserAuthValid, setUserAuth, generateBasePath } from './configService';\nimport { refreshAccessToken } from './farseerService';\nimport { logger } from '../utils/logger';\n\n/**\n * Check if an error is an authentication error (401/403)\n */\nexport function isAuthError(error: unknown): boolean {\n if (error instanceof Error) {\n const msg = error.message.toLowerCase();\n return msg.includes('401') || msg.includes('403') || msg.includes('unauthorized') || msg.includes('forbidden');\n }\n return false;\n}\n\n/**\n * Show a consistent \"please login\" message\n */\nexport function showLoginPrompt(tenant?: string): void {\n logger.error('Authentication required.');\n if (tenant) {\n logger.dim(`No valid credentials found for tenant \"${tenant}\".`);\n }\n logger.info('Run \"farseer login\" to authenticate via browser.');\n logger.dim('Or use \"farseer config set <tenant> --api-key <key>\" for API key auth.');\n}\n\nexport interface FileMetadata {\n uploadTime?: string; // ISO timestamp\n uploader?: {\n id: number;\n email: string;\n firstName: string;\n lastName: string;\n };\n size?: number;\n}\n\n/**\n * Canonical RemoteFile shape used by every layer of the CLI. Both\n * FarseerApi (JWT path) and FarseerService (API-key path) re-export this\n * type so downstream code (SyncService, MCP tools, tests) can rely on a\n * single definition. Earlier each layer declared its own copy that drifted\n * \u2014 three different shapes that disagreed on which optional fields existed,\n * which made it impossible to tell from a function signature what the\n * caller could assume was set.\n *\n * Optional fields are populated lazily:\n * - `content` \u2014 only set by callers that already fetched body bytes\n * (some legacy paths combined list + download in a single helper).\n * - `metadata` \u2014 populated by listFiles for the JWT path. The API-key\n * path doesn't return it, so consumers must handle absence.\n */\nexport interface RemoteFile {\n name: string;\n path: string;\n reference: string;\n content?: string;\n metadata?: FileMetadata;\n}\n\n// Default file extensions to sync (scripts only).\n//\n// Kept in lockstep with the backend's FILE_EXTENSION_WHITELIST: only formats\n// the server actually accepts can be a default. `.mjs` / `.cjs` are NOT in\n// the backend whitelist (see fileValidation.ts \u2192 BACKEND_EXTENSION_WHITELIST\n// and `farseer/backend/app/openapi/v3/services/farseerFileService.ts`), so\n// including them here meant a default `farseer push` would scoop them up,\n// pre-flight would reject them, and the user got \"extension not allowed\"\n// for a file they never explicitly asked us to sync. Drop them.\nexport const DEFAULT_SCRIPT_EXTENSIONS = ['.ts', '.js'];\n\nimport { AppArgument, AppListItem, RemoteApp, ModelExport, ModelExportOptions, ModelExportTable } from './farseerApi';\n\n// Common interface that both FarseerService and FarseerApi implement\nexport interface IFarseerClient {\n testConnection(): Promise<boolean>;\n getFilesFolder(): Promise<{ id: number; name: string; type: string } | null>;\n listFiles(folderPath?: string[]): Promise<RemoteFile[]>;\n getFileContent(reference: string): Promise<string>;\n getFileContentAsBuffer(reference: string): Promise<Buffer>;\n createFile(content: string | Buffer, fileName: string, folderPath?: string[]): Promise<void>;\n updateFile(reference: string, content: string | Buffer, fileName: string): Promise<void>;\n deleteFile(reference: string): Promise<void>;\n getFileByPath(filePath: string): Promise<RemoteFile | null>;\n getFileMetadata(reference: string): Promise<FileMetadata | null>;\n isTextFile(filename: string): boolean;\n isBinaryFile(filename: string): boolean;\n // Apps API methods\n listApps(): Promise<AppListItem[]>;\n getApp(referenceId: string): Promise<RemoteApp | null>;\n getAppByName(name: string): Promise<RemoteApp | null>;\n createApp(name: string): Promise<RemoteApp>;\n updateApp(\n referenceId: string,\n update: {\n name?: string;\n description?: string;\n expectedArguments?: AppArgument[];\n mainScriptFileId?: string | null;\n scriptFileIds?: string[];\n },\n ): Promise<RemoteApp>;\n deleteApp(referenceId: string): Promise<void>;\n getScriptFiles(): Promise<{ id: string; name: string }[]>;\n // Model export\n exportModel(options?: ModelExportOptions): Promise<ModelExport>;\n /**\n * Fetch a single dimension table with its members. Goes through\n * `entities/search` + `getRelations` + `getMany`, which scope the\n * fetch to one table \u2014 unlike `exportModel` with `tableGids`,\n * which currently 500s for some tables on large tenants\n * (rama-side scoping bug, tracked separately).\n */\n loadDimensionTableWithMembers(name: string): Promise<ModelExportTable | null>;\n // Token management (optional - only FarseerApi implements this)\n updateAccessToken?(newToken: string): void;\n}\n\nexport interface FarseerClientResult {\n client: IFarseerClient;\n authType: 'apiKey' | 'jwt';\n}\n\n/**\n * Get a Farseer client for the given organisation and tenant.\n * Tries JWT token first (supports apps), then falls back to API key.\n *\n * @param organisation - The organisation hostname (e.g., \"jgl\" for jgl.farseer.io)\n * @param tenant - Tenant name for X-TENANT-ID header (e.g., \"tt-hotels-hr-dev\")\n */\nexport async function getFarseerClient(organisation: string, tenant: string): Promise<FarseerClientResult | null> {\n // 1. Try JWT token from browser login first (supports apps sync)\n const auth = getUserAuth();\n if (auth) {\n // Check if token needs refresh\n let accessToken = auth.accessToken;\n if (!isUserAuthValid()) {\n logger.dim('Token expired, refreshing...');\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n if (!refreshed) {\n logger.warning('Could not refresh token. Please login again with: farseer login');\n // Fall through to API key\n } else {\n // Save refreshed token\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n accessToken = refreshed.accessToken;\n logger.dim('Token refreshed');\n }\n }\n\n if (isUserAuthValid()) {\n return {\n client: new FarseerApi(accessToken, organisation, tenant),\n authType: 'jwt',\n };\n }\n }\n\n // 2. Fall back to API key config\n const credential = getCredential(tenant);\n if (credential) {\n return {\n client: new FarseerService(credential),\n authType: 'apiKey',\n };\n }\n\n return null;\n}\n\n/**\n * Check what authentication methods are available\n */\nexport function getAvailableAuth(tenant: string): {\n hasApiKey: boolean;\n hasJwt: boolean;\n jwtValid: boolean;\n} {\n const credential = getCredential(tenant);\n const auth = getUserAuth();\n\n return {\n hasApiKey: !!credential,\n hasJwt: !!auth,\n jwtValid: isUserAuthValid(),\n };\n}\n\n/**\n * Get a Farseer client with automatic fallback and connection testing.\n * This is the recommended way to get a client for commands.\n *\n * Flow:\n * 1. Try JWT if available and valid\n * 2. If JWT fails or unavailable, try API key\n * 3. If nothing works, return null (caller should show login prompt)\n *\n * @param organisation - The organisation hostname (e.g., \"jgl\" for jgl.farseer.io)\n * @param tenant - Tenant name for X-TENANT-ID header (e.g., \"tt-hotels-hr-dev\")\n */\nexport async function getFarseerClientWithFallback(\n organisation: string,\n tenant: string,\n): Promise<FarseerClientResult | null> {\n const auth = getUserAuth();\n const credential = getCredential(tenant);\n\n // 1. Try JWT token first\n if (auth) {\n let accessToken = auth.accessToken;\n\n // Refresh token if needed\n if (!isUserAuthValid()) {\n logger.dim('Token expired, refreshing...');\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n if (refreshed) {\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n accessToken = refreshed.accessToken;\n logger.dim('Token refreshed');\n }\n }\n\n if (isUserAuthValid()) {\n const jwtClient = new FarseerApi(accessToken, organisation, tenant);\n\n // Test JWT connection\n try {\n const connected = await jwtClient.testConnection();\n if (connected) {\n return { client: jwtClient, authType: 'jwt' };\n }\n } catch (error) {\n // JWT failed, will try API key\n logger.dim('JWT auth failed for this tenant, trying API key...');\n }\n }\n }\n\n // 2. Try API key\n if (credential) {\n const apiKeyClient = new FarseerService(credential);\n\n try {\n const connected = await apiKeyClient.testConnection();\n if (connected) {\n return { client: apiKeyClient, authType: 'apiKey' };\n }\n } catch {\n // API key also failed\n logger.dim('API key auth failed.');\n }\n }\n\n // 3. Nothing worked\n return null;\n}\n\n/**\n * Ensure the token is fresh and update the client if needed.\n * Call this before long-running operations to avoid token expiration.\n *\n * @returns true if token was refreshed, false if no refresh needed or API key auth\n */\nexport async function ensureFreshToken(client: IFarseerClient): Promise<boolean> {\n const auth = getUserAuth();\n if (!auth) {\n return false; // No JWT auth, probably using API key\n }\n\n // Check if token needs refresh (give 30 second buffer)\n const expiresAt = new Date(auth.expiresAt);\n const now = new Date();\n const bufferMs = 30 * 1000; // 30 seconds\n\n if (expiresAt.getTime() - now.getTime() > bufferMs) {\n return false; // Token is still fresh enough\n }\n\n // Refresh the token\n logger.dim('Refreshing token before operation...');\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n\n if (!refreshed) {\n logger.warning('Could not refresh token.');\n return false;\n }\n\n // Save the new token\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n\n // Update the client's token if it supports it\n if (client.updateAccessToken) {\n client.updateAccessToken(refreshed.accessToken);\n logger.dim('Token refreshed');\n return true;\n }\n\n return false;\n}\n\n/**\n * Get a native farseer-client FarseerClient instance.\n * This provides access to the full farseer-client API (export, import jobs, file creation, etc.)\n * that isn't available through the simplified IFarseerClient interface.\n *\n * Tries JWT first, then API key. Handles token refresh automatically.\n *\n * @param organisation - The organisation hostname (e.g., \"jgl\" for jgl.farseer.io)\n * @param tenant - Tenant name for X-TENANT-ID header\n */\nexport async function getNativeFarseerClient(\n organisation: string,\n tenant: string,\n): Promise<farseer.FarseerClient | null> {\n const basePath = generateBasePath(organisation);\n\n // 1. Try JWT token first\n const auth = getUserAuth();\n if (auth) {\n let accessToken = auth.accessToken;\n\n if (!isUserAuthValid()) {\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n if (refreshed) {\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n accessToken = refreshed.accessToken;\n }\n }\n\n if (isUserAuthValid()) {\n return new farseer.FarseerClient({\n basePath,\n headers: {\n 'X-TENANT-ID': tenant,\n Authorization: `Bearer ${accessToken}`,\n },\n });\n }\n }\n\n // 2. Try API key\n const credential = getCredential(tenant);\n if (credential) {\n return new farseer.FarseerClient({\n basePath: credential.basePath,\n headers: {\n 'X-TENANT-ID': credential.tenantId,\n 'X-API-KEY': credential.apiKey,\n },\n });\n }\n\n return null;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,cAAyB;AACzB,4BAA+B;AAC/B,wBAA2B;AAC3B,2BAA2F;AAC3F,IAAAA,yBAAmC;AACnC,oBAAuB;AAKhB,SAAS,YAAY,OAAyB;AACjD,MAAI,iBAAiB,OAAO;AACxB,UAAM,MAAM,MAAM,QAAQ,YAAY;AACtC,WAAO,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,cAAc,KAAK,IAAI,SAAS,WAAW;AAAA,EACjH;AACA,SAAO;AACX;AAKO,SAAS,gBAAgB,QAAuB;AACnD,uBAAO,MAAM,0BAA0B;AACvC,MAAI,QAAQ;AACR,yBAAO,IAAI,0CAA0C,MAAM,IAAI;AAAA,EACnE;AACA,uBAAO,KAAK,kDAAkD;AAC9D,uBAAO,IAAI,wEAAwE;AACvF;
|
|
4
|
+
"sourcesContent": ["/**\n * Factory for creating Farseer API client based on available authentication\n *\n * Priority:\n * 1. JWT token (from browser login) - try first\n * 2. API key (from config) - fallback if JWT fails or unavailable\n * 3. Prompt user to login - if nothing works\n */\n\nimport * as farseer from 'farseer-client';\nimport { FarseerService } from './farseerService';\nimport { FarseerApi } from './farseerApi';\nimport { getCredential, getUserAuth, isUserAuthValid, setUserAuth, generateBasePath } from './configService';\nimport { refreshAccessToken } from './farseerService';\nimport { logger } from '../utils/logger';\n\n/**\n * Check if an error is an authentication error (401/403)\n */\nexport function isAuthError(error: unknown): boolean {\n if (error instanceof Error) {\n const msg = error.message.toLowerCase();\n return msg.includes('401') || msg.includes('403') || msg.includes('unauthorized') || msg.includes('forbidden');\n }\n return false;\n}\n\n/**\n * Show a consistent \"please login\" message\n */\nexport function showLoginPrompt(tenant?: string): void {\n logger.error('Authentication required.');\n if (tenant) {\n logger.dim(`No valid credentials found for tenant \"${tenant}\".`);\n }\n logger.info('Run \"farseer login\" to authenticate via browser.');\n logger.dim('Or use \"farseer config set <tenant> --api-key <key>\" for API key auth.');\n}\n\nexport interface FileMetadata {\n uploadTime?: string; // ISO timestamp\n uploader?: {\n id: number;\n email: string;\n firstName: string;\n lastName: string;\n };\n size?: number;\n}\n\n/**\n * Canonical RemoteFile shape used by every layer of the CLI. Both\n * FarseerApi (JWT path) and FarseerService (API-key path) re-export this\n * type so downstream code (SyncService, MCP tools, tests) can rely on a\n * single definition. Earlier each layer declared its own copy that drifted\n * \u2014 three different shapes that disagreed on which optional fields existed,\n * which made it impossible to tell from a function signature what the\n * caller could assume was set.\n *\n * Optional fields are populated lazily:\n * - `content` \u2014 only set by callers that already fetched body bytes\n * (some legacy paths combined list + download in a single helper).\n * - `metadata` \u2014 populated by listFiles for the JWT path. The API-key\n * path doesn't return it, so consumers must handle absence.\n */\nexport interface RemoteFile {\n name: string;\n path: string;\n reference: string;\n content?: string;\n metadata?: FileMetadata;\n}\n\n// Narrow set of \"script\" extensions \u2014 used by `farseer files list` and\n// `farseer list` to default to source-code style files when listing a\n// folder. NOT the default sync scope; see DEFAULT_SYNC_EXTENSIONS below.\nexport const DEFAULT_SCRIPT_EXTENSIONS = ['.ts', '.js'];\n\n// Default sync scope \u2014 the curated set of files a developer AUTHORS in an\n// editor. NARROWER than the backend's accepted extension list\n// (`cli/src/utils/fileValidation.ts:BACKEND_EXTENSION_WHITELIST`, which\n// mirrors `farseer/backend/app/openapi/v3/services/farseerFileService.ts`).\n// The earlier \"default sync = everything backend accepts\" expanded the\n// default scope to 25 entries including binary / data formats (.csv,\n// .parquet, .xlsx, .pdf, images) \u2014 large files no one edits in a code\n// editor that dominated first-pull time and made `status` noisy.\n//\n// Users opt into the rest of the backend whitelist (data / docs /\n// archives) via `--include-ext <ext>` or persistent\n// `farseer config include`. Anything still outside the backend whitelist\n// requires `--all` or `--include-folder`.\n//\n// Subset contract: every entry here must also be in\n// `BACKEND_EXTENSION_WHITELIST`, otherwise push pre-flight will reject\n// in-scope files (extension not allowed) \u2014 defeats the purpose of the\n// default scope. Asserted by `defaultSyncExtensionsParity.test.ts`.\nexport const DEFAULT_SYNC_EXTENSIONS = [\n // Code (frontend / scripts)\n '.ts',\n '.js',\n // Code (Python)\n '.py',\n // Config / data\n '.yml',\n '.yaml',\n '.json',\n // Docs\n '.md',\n];\n\nimport { AppArgument, AppListItem, RemoteApp, ModelExport, ModelExportOptions, ModelExportTable } from './farseerApi';\n\n// Common interface that both FarseerService and FarseerApi implement\nexport interface IFarseerClient {\n testConnection(): Promise<boolean>;\n getFilesFolder(): Promise<{ id: number; name: string; type: string } | null>;\n listFiles(folderPath?: string[]): Promise<RemoteFile[]>;\n getFileContent(reference: string): Promise<string>;\n getFileContentAsBuffer(reference: string): Promise<Buffer>;\n createFile(content: string | Buffer, fileName: string, folderPath?: string[]): Promise<void>;\n updateFile(reference: string, content: string | Buffer, fileName: string): Promise<void>;\n deleteFile(reference: string): Promise<void>;\n getFileByPath(filePath: string): Promise<RemoteFile | null>;\n getFileMetadata(reference: string): Promise<FileMetadata | null>;\n isTextFile(filename: string): boolean;\n isBinaryFile(filename: string): boolean;\n // Apps API methods\n listApps(): Promise<AppListItem[]>;\n getApp(referenceId: string): Promise<RemoteApp | null>;\n getAppByName(name: string): Promise<RemoteApp | null>;\n createApp(name: string): Promise<RemoteApp>;\n updateApp(\n referenceId: string,\n update: {\n name?: string;\n description?: string;\n expectedArguments?: AppArgument[];\n mainScriptFileId?: string | null;\n scriptFileIds?: string[];\n },\n ): Promise<RemoteApp>;\n deleteApp(referenceId: string): Promise<void>;\n getScriptFiles(): Promise<{ id: string; name: string }[]>;\n // Model export\n exportModel(options?: ModelExportOptions): Promise<ModelExport>;\n /**\n * Fetch a single dimension table with its members. Goes through\n * `entities/search` + `getRelations` + `getMany`, which scope the\n * fetch to one table \u2014 unlike `exportModel` with `tableGids`,\n * which currently 500s for some tables on large tenants\n * (rama-side scoping bug, tracked separately).\n */\n loadDimensionTableWithMembers(name: string): Promise<ModelExportTable | null>;\n // Token management (optional - only FarseerApi implements this)\n updateAccessToken?(newToken: string): void;\n}\n\nexport interface FarseerClientResult {\n client: IFarseerClient;\n authType: 'apiKey' | 'jwt';\n}\n\n/**\n * Get a Farseer client for the given organisation and tenant.\n * Tries JWT token first (supports apps), then falls back to API key.\n *\n * @param organisation - The organisation hostname (e.g., \"jgl\" for jgl.farseer.io)\n * @param tenant - Tenant name for X-TENANT-ID header (e.g., \"tt-hotels-hr-dev\")\n */\nexport async function getFarseerClient(organisation: string, tenant: string): Promise<FarseerClientResult | null> {\n // 1. Try JWT token from browser login first (supports apps sync)\n const auth = getUserAuth();\n if (auth) {\n // Check if token needs refresh\n let accessToken = auth.accessToken;\n if (!isUserAuthValid()) {\n logger.dim('Token expired, refreshing...');\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n if (!refreshed) {\n logger.warning('Could not refresh token. Please login again with: farseer login');\n // Fall through to API key\n } else {\n // Save refreshed token\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n accessToken = refreshed.accessToken;\n logger.dim('Token refreshed');\n }\n }\n\n if (isUserAuthValid()) {\n return {\n client: new FarseerApi(accessToken, organisation, tenant),\n authType: 'jwt',\n };\n }\n }\n\n // 2. Fall back to API key config\n const credential = getCredential(tenant);\n if (credential) {\n return {\n client: new FarseerService(credential),\n authType: 'apiKey',\n };\n }\n\n return null;\n}\n\n/**\n * Check what authentication methods are available\n */\nexport function getAvailableAuth(tenant: string): {\n hasApiKey: boolean;\n hasJwt: boolean;\n jwtValid: boolean;\n} {\n const credential = getCredential(tenant);\n const auth = getUserAuth();\n\n return {\n hasApiKey: !!credential,\n hasJwt: !!auth,\n jwtValid: isUserAuthValid(),\n };\n}\n\n/**\n * Get a Farseer client with automatic fallback and connection testing.\n * This is the recommended way to get a client for commands.\n *\n * Flow:\n * 1. Try JWT if available and valid\n * 2. If JWT fails or unavailable, try API key\n * 3. If nothing works, return null (caller should show login prompt)\n *\n * @param organisation - The organisation hostname (e.g., \"jgl\" for jgl.farseer.io)\n * @param tenant - Tenant name for X-TENANT-ID header (e.g., \"tt-hotels-hr-dev\")\n */\nexport async function getFarseerClientWithFallback(\n organisation: string,\n tenant: string,\n): Promise<FarseerClientResult | null> {\n const auth = getUserAuth();\n const credential = getCredential(tenant);\n\n // 1. Try JWT token first\n if (auth) {\n let accessToken = auth.accessToken;\n\n // Refresh token if needed\n if (!isUserAuthValid()) {\n logger.dim('Token expired, refreshing...');\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n if (refreshed) {\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n accessToken = refreshed.accessToken;\n logger.dim('Token refreshed');\n }\n }\n\n if (isUserAuthValid()) {\n const jwtClient = new FarseerApi(accessToken, organisation, tenant);\n\n // Test JWT connection\n try {\n const connected = await jwtClient.testConnection();\n if (connected) {\n return { client: jwtClient, authType: 'jwt' };\n }\n } catch (error) {\n // JWT failed, will try API key\n logger.dim('JWT auth failed for this tenant, trying API key...');\n }\n }\n }\n\n // 2. Try API key\n if (credential) {\n const apiKeyClient = new FarseerService(credential);\n\n try {\n const connected = await apiKeyClient.testConnection();\n if (connected) {\n return { client: apiKeyClient, authType: 'apiKey' };\n }\n } catch {\n // API key also failed\n logger.dim('API key auth failed.');\n }\n }\n\n // 3. Nothing worked\n return null;\n}\n\n/**\n * Ensure the token is fresh and update the client if needed.\n * Call this before long-running operations to avoid token expiration.\n *\n * @returns true if token was refreshed, false if no refresh needed or API key auth\n */\nexport async function ensureFreshToken(client: IFarseerClient): Promise<boolean> {\n const auth = getUserAuth();\n if (!auth) {\n return false; // No JWT auth, probably using API key\n }\n\n // Check if token needs refresh (give 30 second buffer)\n const expiresAt = new Date(auth.expiresAt);\n const now = new Date();\n const bufferMs = 30 * 1000; // 30 seconds\n\n if (expiresAt.getTime() - now.getTime() > bufferMs) {\n return false; // Token is still fresh enough\n }\n\n // Refresh the token\n logger.dim('Refreshing token before operation...');\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n\n if (!refreshed) {\n logger.warning('Could not refresh token.');\n return false;\n }\n\n // Save the new token\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n\n // Update the client's token if it supports it\n if (client.updateAccessToken) {\n client.updateAccessToken(refreshed.accessToken);\n logger.dim('Token refreshed');\n return true;\n }\n\n return false;\n}\n\n/**\n * Get a native farseer-client FarseerClient instance.\n * This provides access to the full farseer-client API (export, import jobs, file creation, etc.)\n * that isn't available through the simplified IFarseerClient interface.\n *\n * Tries JWT first, then API key. Handles token refresh automatically.\n *\n * @param organisation - The organisation hostname (e.g., \"jgl\" for jgl.farseer.io)\n * @param tenant - Tenant name for X-TENANT-ID header\n */\nexport async function getNativeFarseerClient(\n organisation: string,\n tenant: string,\n): Promise<farseer.FarseerClient | null> {\n const basePath = generateBasePath(organisation);\n\n // 1. Try JWT token first\n const auth = getUserAuth();\n if (auth) {\n let accessToken = auth.accessToken;\n\n if (!isUserAuthValid()) {\n const refreshed = await refreshAccessToken(auth.refreshToken, auth.realm || 'master');\n if (refreshed) {\n setUserAuth({\n accessToken: refreshed.accessToken,\n refreshToken: refreshed.refreshToken,\n expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),\n realm: auth.realm,\n });\n accessToken = refreshed.accessToken;\n }\n }\n\n if (isUserAuthValid()) {\n return new farseer.FarseerClient({\n basePath,\n headers: {\n 'X-TENANT-ID': tenant,\n Authorization: `Bearer ${accessToken}`,\n },\n });\n }\n }\n\n // 2. Try API key\n const credential = getCredential(tenant);\n if (credential) {\n return new farseer.FarseerClient({\n basePath: credential.basePath,\n headers: {\n 'X-TENANT-ID': credential.tenantId,\n 'X-API-KEY': credential.apiKey,\n },\n });\n }\n\n return null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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;AACzB,MAAI,MAAM;AACN,QAAI,cAAc,KAAK;AAEvB,QAAI,KAAC,sCAAgB,GAAG;AACpB,YAAM,YAAY,UAAM,2CAAmB,KAAK,cAAc,KAAK,SAAS,QAAQ;AACpF,UAAI,WAAW;AACX,8CAAY;AAAA,UACR,aAAa,UAAU;AAAA,UACvB,cAAc,UAAU;AAAA,UACxB,WAAW,IAAI,KAAK,KAAK,IAAI,IAAI,UAAU,YAAY,GAAI,EAAE,YAAY;AAAA,UACzE,OAAO,KAAK;AAAA,QAChB,CAAC;AACD,sBAAc,UAAU;AAAA,MAC5B;AAAA,IACJ;AAEA,YAAI,sCAAgB,GAAG;AACnB,aAAO,IAAI,QAAQ,cAAc;AAAA,QAC7B;AAAA,QACA,SAAS;AAAA,UACL,eAAe;AAAA,UACf,eAAe,UAAU,WAAW;AAAA,QACxC;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AAGA,QAAM,iBAAa,oCAAc,MAAM;AACvC,MAAI,YAAY;AACZ,WAAO,IAAI,QAAQ,cAAc;AAAA,MAC7B,UAAU,WAAW;AAAA,MACrB,SAAS;AAAA,QACL,eAAe,WAAW;AAAA,QAC1B,aAAa,WAAW;AAAA,MAC5B;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO;AACX;",
|
|
6
6
|
"names": ["import_farseerService"]
|
|
7
7
|
}
|
|
@@ -32,6 +32,8 @@ __export(syncService_exports, {
|
|
|
32
32
|
MERGE_MARKER_REMOTE_END: () => MERGE_MARKER_REMOTE_END,
|
|
33
33
|
MERGE_MARKER_SEPARATOR: () => MERGE_MARKER_SEPARATOR,
|
|
34
34
|
SyncService: () => SyncService,
|
|
35
|
+
buildHiddenDirSkipper: () => buildHiddenDirSkipper,
|
|
36
|
+
classifyIgnoredFile: () => classifyIgnoredFile,
|
|
35
37
|
isHiddenFile: () => import_helpers2.isHiddenFile,
|
|
36
38
|
isOsMetadataFile: () => import_helpers2.isOsMetadataFile,
|
|
37
39
|
shouldIncludeFile: () => shouldIncludeFile
|
|
@@ -45,18 +47,96 @@ var import_helpers = require("../utils/helpers");
|
|
|
45
47
|
var import_logger = require("../utils/logger");
|
|
46
48
|
var import_fileValidation = require("../utils/fileValidation");
|
|
47
49
|
var import_errorFormatter = require("../utils/errorFormatter");
|
|
50
|
+
var import_syncReporting = require("../utils/syncReporting");
|
|
48
51
|
var import_helpers2 = require("../utils/helpers");
|
|
52
|
+
const IGNORED_FOLDER_BLOCKLIST = ["node_modules", "dist", "build", "bower_components", "coverage", "__pycache__"];
|
|
53
|
+
function classifyIgnoredFile(filePath) {
|
|
54
|
+
const segments = filePath.split("/");
|
|
55
|
+
for (const seg of segments) {
|
|
56
|
+
if (IGNORED_FOLDER_BLOCKLIST.includes(seg)) return "blocklistedFolder";
|
|
57
|
+
}
|
|
58
|
+
return "unsupportedExtension";
|
|
59
|
+
}
|
|
60
|
+
function buildHiddenDirSkipper(options, configFolders) {
|
|
61
|
+
const normalize = (f) => f.split(path.sep).join("/").replace(/^\/+|\/+$/g, "");
|
|
62
|
+
const includeFolders = [...options?.includeFolders ?? [], ...configFolders].map(
|
|
63
|
+
(f) => f.split(path.sep).join("/").replace(/\/+$/, "")
|
|
64
|
+
);
|
|
65
|
+
const onlyFilesPosix = (options?.onlyFiles ?? []).map(normalize);
|
|
66
|
+
return (relPath) => {
|
|
67
|
+
const posix = relPath.split(path.sep).join("/");
|
|
68
|
+
if (!(0, import_helpers.isHiddenFile)(posix)) return false;
|
|
69
|
+
for (const include of includeFolders) {
|
|
70
|
+
if (posix === include) return false;
|
|
71
|
+
if (posix.startsWith(include + "/")) return false;
|
|
72
|
+
if (include.startsWith(posix + "/")) return false;
|
|
73
|
+
}
|
|
74
|
+
for (const only of onlyFilesPosix) {
|
|
75
|
+
if (only === posix) return false;
|
|
76
|
+
if (only.startsWith(posix + "/")) return false;
|
|
77
|
+
if (posix.startsWith(only + "/")) return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const ANY_DEPTH_BLOCKLIST = ["node_modules/", "bower_components/", "__snapshots__/", "__pycache__/"];
|
|
83
|
+
const ROOT_ONLY_BLOCKLIST = [
|
|
84
|
+
// JS / Node — build output at project root
|
|
85
|
+
"dist/",
|
|
86
|
+
"build/",
|
|
87
|
+
"out/",
|
|
88
|
+
// Next.js static export
|
|
89
|
+
".next/",
|
|
90
|
+
".cache/",
|
|
91
|
+
".turbo/",
|
|
92
|
+
".parcel-cache/",
|
|
93
|
+
".svelte-kit/",
|
|
94
|
+
// Test coverage
|
|
95
|
+
"coverage/",
|
|
96
|
+
// Python — venv, tool caches at project root
|
|
97
|
+
"venv/",
|
|
98
|
+
".venv/",
|
|
99
|
+
".pytest_cache/",
|
|
100
|
+
".mypy_cache/",
|
|
101
|
+
".tox/",
|
|
102
|
+
// Go / Rust / JVM — vendored deps and build artefacts at project root
|
|
103
|
+
"vendor/",
|
|
104
|
+
"target/",
|
|
105
|
+
".gradle/",
|
|
106
|
+
// IaC / cloud SDK caches
|
|
107
|
+
".terraform/",
|
|
108
|
+
".serverless/",
|
|
109
|
+
".aws-sam/",
|
|
110
|
+
// IDE state
|
|
111
|
+
".idea/",
|
|
112
|
+
// Scratch
|
|
113
|
+
"tmp/",
|
|
114
|
+
"temp/"
|
|
115
|
+
];
|
|
116
|
+
function isBlocklistedPath(filePath) {
|
|
117
|
+
if (ANY_DEPTH_BLOCKLIST.some((prefix) => filePath.startsWith(prefix) || filePath.includes("/" + prefix))) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return ROOT_ONLY_BLOCKLIST.some((prefix) => filePath.startsWith(prefix));
|
|
121
|
+
}
|
|
122
|
+
function toPosix(filePath) {
|
|
123
|
+
return filePath.replace(/\\/g, "/");
|
|
124
|
+
}
|
|
49
125
|
function shouldIncludeFile(filePath, tenant, options) {
|
|
126
|
+
filePath = toPosix(filePath);
|
|
50
127
|
if ((0, import_helpers.isOsMetadataFile)(filePath)) return false;
|
|
51
128
|
if (options?.onlyFiles && options.onlyFiles.length > 0) {
|
|
52
129
|
return options.onlyFiles.includes(filePath);
|
|
53
130
|
}
|
|
54
131
|
const ext = path.extname(filePath).toLowerCase();
|
|
55
132
|
const persistent = (0, import_configService.getSyncIncludes)(tenant);
|
|
56
|
-
const
|
|
57
|
-
if ((0, import_helpers.isHiddenFile)(filePath)) return
|
|
133
|
+
const folderMatches = (options?.includeFolders?.some((f) => filePath.startsWith(toPosix(f) + "/") || filePath === toPosix(f)) ?? false) || (persistent?.folders?.some((f) => filePath.startsWith(toPosix(f) + "/") || filePath === toPosix(f)) ?? false);
|
|
134
|
+
if ((0, import_helpers.isHiddenFile)(filePath)) return folderMatches;
|
|
135
|
+
const extensionMatches = (options?.includeExtensions?.includes(ext) ?? false) || (persistent?.extensions?.includes(ext) ?? false);
|
|
136
|
+
const matchesIncludes = folderMatches || extensionMatches;
|
|
137
|
+
if (isBlocklistedPath(filePath)) return matchesIncludes;
|
|
58
138
|
if (options?.all) return true;
|
|
59
|
-
if (import_farseerFactory.
|
|
139
|
+
if (import_farseerFactory.DEFAULT_SYNC_EXTENSIONS.includes(ext)) return true;
|
|
60
140
|
return matchesIncludes;
|
|
61
141
|
}
|
|
62
142
|
function emptyStatus(deepCompare) {
|
|
@@ -69,7 +149,10 @@ function emptyStatus(deepCompare) {
|
|
|
69
149
|
deletedRemotely: [],
|
|
70
150
|
inSync: [],
|
|
71
151
|
conflicts: [],
|
|
72
|
-
deepCompare
|
|
152
|
+
deepCompare,
|
|
153
|
+
ignoredLocal: [],
|
|
154
|
+
ignoredLocalTotal: 0,
|
|
155
|
+
ignoredLocalTotalByReason: { unsupportedExtension: 0, blocklistedFolder: 0 }
|
|
73
156
|
};
|
|
74
157
|
}
|
|
75
158
|
const MERGE_MARKER_LOCAL_START = "<<<<<<< LOCAL (your version)";
|
|
@@ -119,7 +202,28 @@ class SyncService {
|
|
|
119
202
|
const deep = options?.deep === true;
|
|
120
203
|
const syncState = this.loadSyncState();
|
|
121
204
|
const filesDir = (0, import_helpers.getTenantFilesDir)(this.tenant);
|
|
122
|
-
const
|
|
205
|
+
const includeFoldersFromConfig = (0, import_configService.getSyncIncludes)(this.tenant)?.folders ?? [];
|
|
206
|
+
const skipHiddenDir = buildHiddenDirSkipper(options, includeFoldersFromConfig);
|
|
207
|
+
const allLocalFiles = (0, import_helpers.getAllFilesInDir)(filesDir, { shouldSkipDir: skipHiddenDir });
|
|
208
|
+
const localFiles = [];
|
|
209
|
+
const ignoredLocal = [];
|
|
210
|
+
let ignoredLocalTotal = 0;
|
|
211
|
+
const ignoredLocalTotalByReason = { unsupportedExtension: 0, blocklistedFolder: 0 };
|
|
212
|
+
const suppressIgnoredLocal = (options?.onlyFiles?.length ?? 0) > 0;
|
|
213
|
+
for (const f of allLocalFiles) {
|
|
214
|
+
if (shouldIncludeFile(f, this.tenant, options)) {
|
|
215
|
+
localFiles.push(f);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if ((0, import_helpers.isOsMetadataFile)(f) || (0, import_helpers.isHiddenFile)(f)) continue;
|
|
219
|
+
if (suppressIgnoredLocal) continue;
|
|
220
|
+
ignoredLocalTotal++;
|
|
221
|
+
const reason = classifyIgnoredFile(f);
|
|
222
|
+
ignoredLocalTotalByReason[reason]++;
|
|
223
|
+
if (ignoredLocal.length < import_syncReporting.IGNORED_LOCAL_CAP) {
|
|
224
|
+
ignoredLocal.push({ path: f, reason });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
123
227
|
const localHashes = /* @__PURE__ */ new Map();
|
|
124
228
|
for (const file of localFiles) {
|
|
125
229
|
const fullPath = (0, import_helpers.safeResolveWithinBase)(filesDir, file);
|
|
@@ -165,6 +269,9 @@ class SyncService {
|
|
|
165
269
|
onlyFiles: options?.onlyFiles
|
|
166
270
|
});
|
|
167
271
|
const status = emptyStatus(deep);
|
|
272
|
+
status.ignoredLocal = ignoredLocal;
|
|
273
|
+
status.ignoredLocalTotal = ignoredLocalTotal;
|
|
274
|
+
status.ignoredLocalTotalByReason = ignoredLocalTotalByReason;
|
|
168
275
|
if (deep) {
|
|
169
276
|
status.remoteHashes = remoteHashes;
|
|
170
277
|
}
|
|
@@ -483,16 +590,36 @@ ${remoteContent}${remoteContent.endsWith("\n") ? "" : "\n"}${MERGE_MARKER_REMOTE
|
|
|
483
590
|
// own atomic operation, and `syncState` is saved in `finally` so
|
|
484
591
|
// already-successful items aren't re-uploaded next run. The
|
|
485
592
|
// caller surfaces this list and exits non-zero on non-empty.
|
|
486
|
-
failed: []
|
|
593
|
+
failed: [],
|
|
594
|
+
ignoredLocal: [],
|
|
595
|
+
ignoredLocalTotal: 0,
|
|
596
|
+
ignoredLocalTotalByReason: { unsupportedExtension: 0, blocklistedFolder: 0 }
|
|
487
597
|
};
|
|
488
598
|
const remoteFiles = (await this.farseerClient.listFiles()).filter((f) => !(0, import_helpers.isOsMetadataFile)(f.path));
|
|
489
599
|
const remoteFileMap = /* @__PURE__ */ new Map();
|
|
490
600
|
for (const file of remoteFiles) {
|
|
491
601
|
remoteFileMap.set(file.path, file);
|
|
492
602
|
}
|
|
493
|
-
const
|
|
603
|
+
const includeFoldersFromConfig = (0, import_configService.getSyncIncludes)(this.tenant)?.folders ?? [];
|
|
604
|
+
const skipHiddenDir = buildHiddenDirSkipper(options, includeFoldersFromConfig);
|
|
605
|
+
const allLocalFiles = (0, import_helpers.getAllFilesInDir)(filesDir, { shouldSkipDir: skipHiddenDir });
|
|
494
606
|
const localPresenceSet = new Set(allLocalFiles);
|
|
495
|
-
const inScopeFiles =
|
|
607
|
+
const inScopeFiles = [];
|
|
608
|
+
const suppressIgnoredLocal = (options?.onlyFiles?.length ?? 0) > 0;
|
|
609
|
+
for (const f of allLocalFiles) {
|
|
610
|
+
if (shouldIncludeFile(f, this.tenant, options)) {
|
|
611
|
+
inScopeFiles.push(f);
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
if (suppressIgnoredLocal) continue;
|
|
615
|
+
if ((0, import_helpers.isOsMetadataFile)(f) || (0, import_helpers.isHiddenFile)(f)) continue;
|
|
616
|
+
result.ignoredLocalTotal++;
|
|
617
|
+
const reason = classifyIgnoredFile(f);
|
|
618
|
+
result.ignoredLocalTotalByReason[reason]++;
|
|
619
|
+
if (result.ignoredLocal.length < import_syncReporting.IGNORED_LOCAL_CAP) {
|
|
620
|
+
result.ignoredLocal.push({ path: f, reason });
|
|
621
|
+
}
|
|
622
|
+
}
|
|
496
623
|
const localContents = /* @__PURE__ */ new Map();
|
|
497
624
|
for (const file of inScopeFiles) {
|
|
498
625
|
const fullPath = (0, import_helpers.safeResolveWithinBase)(filesDir, file);
|
|
@@ -851,6 +978,8 @@ ${remoteContent}${remoteContent.endsWith("\n") ? "" : "\n"}${MERGE_MARKER_REMOTE
|
|
|
851
978
|
MERGE_MARKER_REMOTE_END,
|
|
852
979
|
MERGE_MARKER_SEPARATOR,
|
|
853
980
|
SyncService,
|
|
981
|
+
buildHiddenDirSkipper,
|
|
982
|
+
classifyIgnoredFile,
|
|
854
983
|
isHiddenFile,
|
|
855
984
|
isOsMetadataFile,
|
|
856
985
|
shouldIncludeFile
|