@forumviriumhelsinki/podio-mcp 2.3.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/LICENSE +21 -0
- package/README.md +491 -0
- package/build/__tests__/integration/setup.integration.d.ts +104 -0
- package/build/__tests__/integration/setup.integration.d.ts.map +1 -0
- package/build/__tests__/integration/setup.integration.js +233 -0
- package/build/__tests__/integration/setup.integration.js.map +1 -0
- package/build/__tests__/mock-data/items-mock-data.d.ts +168 -0
- package/build/__tests__/mock-data/items-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/items-mock-data.js +370 -0
- package/build/__tests__/mock-data/items-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/notification-mock-data.d.ts +55 -0
- package/build/__tests__/mock-data/notification-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/notification-mock-data.js +190 -0
- package/build/__tests__/mock-data/notification-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/project-epic-mock-data.d.ts +45 -0
- package/build/__tests__/mock-data/project-epic-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/project-epic-mock-data.js +85 -0
- package/build/__tests__/mock-data/project-epic-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/tasks-mock-data.d.ts +27 -0
- package/build/__tests__/mock-data/tasks-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/tasks-mock-data.js +104 -0
- package/build/__tests__/mock-data/tasks-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/utility-mock-data.d.ts +19 -0
- package/build/__tests__/mock-data/utility-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/utility-mock-data.js +165 -0
- package/build/__tests__/mock-data/utility-mock-data.js.map +1 -0
- package/build/__tests__/setup.d.ts +8 -0
- package/build/__tests__/setup.d.ts.map +1 -0
- package/build/__tests__/setup.js +31 -0
- package/build/__tests__/setup.js.map +1 -0
- package/build/__tests__/utils/test-helpers.d.ts +110 -0
- package/build/__tests__/utils/test-helpers.d.ts.map +1 -0
- package/build/__tests__/utils/test-helpers.js +222 -0
- package/build/__tests__/utils/test-helpers.js.map +1 -0
- package/build/api/podio-api-client.d.ts +364 -0
- package/build/api/podio-api-client.d.ts.map +1 -0
- package/build/api/podio-api-client.js +696 -0
- package/build/api/podio-api-client.js.map +1 -0
- package/build/cache/app-cache.d.ts +77 -0
- package/build/cache/app-cache.d.ts.map +1 -0
- package/build/cache/app-cache.js +230 -0
- package/build/cache/app-cache.js.map +1 -0
- package/build/cache/base-cache-manager.d.ts +149 -0
- package/build/cache/base-cache-manager.d.ts.map +1 -0
- package/build/cache/base-cache-manager.js +312 -0
- package/build/cache/base-cache-manager.js.map +1 -0
- package/build/cache/cache-manager.d.ts +230 -0
- package/build/cache/cache-manager.d.ts.map +1 -0
- package/build/cache/cache-manager.js +362 -0
- package/build/cache/cache-manager.js.map +1 -0
- package/build/cache/cache-test.d.ts +9 -0
- package/build/cache/cache-test.d.ts.map +1 -0
- package/build/cache/cache-test.js +169 -0
- package/build/cache/cache-test.js.map +1 -0
- package/build/cache/index.d.ts +18 -0
- package/build/cache/index.d.ts.map +1 -0
- package/build/cache/index.js +20 -0
- package/build/cache/index.js.map +1 -0
- package/build/cache/migration-helper.d.ts +44 -0
- package/build/cache/migration-helper.d.ts.map +1 -0
- package/build/cache/migration-helper.js +235 -0
- package/build/cache/migration-helper.js.map +1 -0
- package/build/cache/project-epic-cache.d.ts +108 -0
- package/build/cache/project-epic-cache.d.ts.map +1 -0
- package/build/cache/project-epic-cache.js +278 -0
- package/build/cache/project-epic-cache.js.map +1 -0
- package/build/cache/space-members-cache.d.ts +99 -0
- package/build/cache/space-members-cache.d.ts.map +1 -0
- package/build/cache/space-members-cache.js +305 -0
- package/build/cache/space-members-cache.js.map +1 -0
- package/build/cache/storage-adapters.d.ts +100 -0
- package/build/cache/storage-adapters.d.ts.map +1 -0
- package/build/cache/storage-adapters.js +297 -0
- package/build/cache/storage-adapters.js.map +1 -0
- package/build/errors/api-errors.d.ts +52 -0
- package/build/errors/api-errors.d.ts.map +1 -0
- package/build/errors/api-errors.js +86 -0
- package/build/errors/api-errors.js.map +1 -0
- package/build/errors/auth-errors.d.ts +67 -0
- package/build/errors/auth-errors.d.ts.map +1 -0
- package/build/errors/auth-errors.js +114 -0
- package/build/errors/auth-errors.js.map +1 -0
- package/build/errors/base.d.ts +102 -0
- package/build/errors/base.d.ts.map +1 -0
- package/build/errors/base.js +131 -0
- package/build/errors/base.js.map +1 -0
- package/build/errors/cache-errors.d.ts +53 -0
- package/build/errors/cache-errors.d.ts.map +1 -0
- package/build/errors/cache-errors.js +83 -0
- package/build/errors/cache-errors.js.map +1 -0
- package/build/errors/config-errors.d.ts +58 -0
- package/build/errors/config-errors.d.ts.map +1 -0
- package/build/errors/config-errors.js +96 -0
- package/build/errors/config-errors.js.map +1 -0
- package/build/errors/index.d.ts +101 -0
- package/build/errors/index.d.ts.map +1 -0
- package/build/errors/index.js +135 -0
- package/build/errors/index.js.map +1 -0
- package/build/errors/structure-errors.d.ts +89 -0
- package/build/errors/structure-errors.d.ts.map +1 -0
- package/build/errors/structure-errors.js +182 -0
- package/build/errors/structure-errors.js.map +1 -0
- package/build/errors/validation-errors.d.ts +81 -0
- package/build/errors/validation-errors.d.ts.map +1 -0
- package/build/errors/validation-errors.js +169 -0
- package/build/errors/validation-errors.js.map +1 -0
- package/build/fields/field-mapper.d.ts +245 -0
- package/build/fields/field-mapper.d.ts.map +1 -0
- package/build/fields/field-mapper.js +404 -0
- package/build/fields/field-mapper.js.map +1 -0
- package/build/index.d.ts +550 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1527 -0
- package/build/index.js.map +1 -0
- package/build/oauth-helper.d.ts +189 -0
- package/build/oauth-helper.d.ts.map +1 -0
- package/build/oauth-helper.js +422 -0
- package/build/oauth-helper.js.map +1 -0
- package/build/services/app-structure-service.d.ts +49 -0
- package/build/services/app-structure-service.d.ts.map +1 -0
- package/build/services/app-structure-service.js +122 -0
- package/build/services/app-structure-service.js.map +1 -0
- package/build/services/code-execution-service.d.ts +88 -0
- package/build/services/code-execution-service.d.ts.map +1 -0
- package/build/services/code-execution-service.js +342 -0
- package/build/services/code-execution-service.js.map +1 -0
- package/build/services/comment-service.d.ts +66 -0
- package/build/services/comment-service.d.ts.map +1 -0
- package/build/services/comment-service.js +139 -0
- package/build/services/comment-service.js.map +1 -0
- package/build/services/index.d.ts +16 -0
- package/build/services/index.d.ts.map +1 -0
- package/build/services/index.js +15 -0
- package/build/services/index.js.map +1 -0
- package/build/services/item-service.d.ts +104 -0
- package/build/services/item-service.d.ts.map +1 -0
- package/build/services/item-service.js +368 -0
- package/build/services/item-service.js.map +1 -0
- package/build/services/notification-service.d.ts +125 -0
- package/build/services/notification-service.d.ts.map +1 -0
- package/build/services/notification-service.js +321 -0
- package/build/services/notification-service.js.map +1 -0
- package/build/services/project-epic-service.d.ts +73 -0
- package/build/services/project-epic-service.d.ts.map +1 -0
- package/build/services/project-epic-service.js +248 -0
- package/build/services/project-epic-service.js.map +1 -0
- package/build/services/response-formatter.d.ts +190 -0
- package/build/services/response-formatter.d.ts.map +1 -0
- package/build/services/response-formatter.js +1221 -0
- package/build/services/response-formatter.js.map +1 -0
- package/build/services/search-service.d.ts +103 -0
- package/build/services/search-service.d.ts.map +1 -0
- package/build/services/search-service.js +273 -0
- package/build/services/search-service.js.map +1 -0
- package/build/services/task-service.d.ts +70 -0
- package/build/services/task-service.d.ts.map +1 -0
- package/build/services/task-service.js +156 -0
- package/build/services/task-service.js.map +1 -0
- package/build/tools/index.d.ts +8 -0
- package/build/tools/index.d.ts.map +1 -0
- package/build/tools/index.js +8 -0
- package/build/tools/index.js.map +1 -0
- package/build/tools/tool-definitions.d.ts +89 -0
- package/build/tools/tool-definitions.d.ts.map +1 -0
- package/build/tools/tool-definitions.js +1167 -0
- package/build/tools/tool-definitions.js.map +1 -0
- package/build/types/api-types.d.ts +106 -0
- package/build/types/api-types.d.ts.map +1 -0
- package/build/types/api-types.js +11 -0
- package/build/types/api-types.js.map +1 -0
- package/build/types/cache-types.d.ts +52 -0
- package/build/types/cache-types.d.ts.map +1 -0
- package/build/types/cache-types.js +12 -0
- package/build/types/cache-types.js.map +1 -0
- package/build/types/index.d.ts +31 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +25 -0
- package/build/types/index.js.map +1 -0
- package/build/types/notification-types.d.ts +154 -0
- package/build/types/notification-types.d.ts.map +1 -0
- package/build/types/notification-types.js +7 -0
- package/build/types/notification-types.js.map +1 -0
- package/build/types/podio-types.d.ts +250 -0
- package/build/types/podio-types.d.ts.map +1 -0
- package/build/types/podio-types.js +11 -0
- package/build/types/podio-types.js.map +1 -0
- package/build/types/search-types.d.ts +188 -0
- package/build/types/search-types.d.ts.map +1 -0
- package/build/types/search-types.js +43 -0
- package/build/types/search-types.js.map +1 -0
- package/build/utils/debug.d.ts +58 -0
- package/build/utils/debug.d.ts.map +1 -0
- package/build/utils/debug.js +147 -0
- package/build/utils/debug.js.map +1 -0
- package/examples/claude-config-example.json +13 -0
- package/package.json +87 -0
- package/scripts/generate-claude-config.js +107 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Code Execution Service
|
|
3
|
+
*
|
|
4
|
+
* This service handles code execution in a sandboxed Deno environment.
|
|
5
|
+
* It provides 60-95% token reduction for complex multi-step operations
|
|
6
|
+
* by processing data in the execution environment instead of passing
|
|
7
|
+
* it through the model context.
|
|
8
|
+
*
|
|
9
|
+
* SECURITY: Uses strict Deno permissions and path validation.
|
|
10
|
+
*/
|
|
11
|
+
import type { PodioApiClient } from '../api/podio-api-client.js';
|
|
12
|
+
import type { CacheManager } from '../cache/cache-manager.js';
|
|
13
|
+
/**
|
|
14
|
+
* Result of code execution
|
|
15
|
+
*/
|
|
16
|
+
export interface CodeExecutionResult {
|
|
17
|
+
success: boolean;
|
|
18
|
+
result?: any;
|
|
19
|
+
error?: string;
|
|
20
|
+
executionTime: number;
|
|
21
|
+
stdout?: string;
|
|
22
|
+
stderr?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for code execution
|
|
26
|
+
*/
|
|
27
|
+
export interface CodeExecutionOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Execution timeout in milliseconds
|
|
30
|
+
* @default 30000
|
|
31
|
+
*/
|
|
32
|
+
timeout?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Context object to pass to the code
|
|
35
|
+
*/
|
|
36
|
+
context?: Record<string, any>;
|
|
37
|
+
/**
|
|
38
|
+
* App ID for context initialization
|
|
39
|
+
*/
|
|
40
|
+
appId?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Service class for handling code execution in Deno sandbox
|
|
44
|
+
*/
|
|
45
|
+
export declare class CodeExecutionService {
|
|
46
|
+
private readonly apiClient;
|
|
47
|
+
private readonly cacheManager;
|
|
48
|
+
private readonly denoPath;
|
|
49
|
+
private readonly mcpServersPath;
|
|
50
|
+
private denoValidated;
|
|
51
|
+
constructor(apiClient: PodioApiClient, cacheManager: CacheManager);
|
|
52
|
+
/**
|
|
53
|
+
* Validate that Deno is installed and accessible
|
|
54
|
+
*/
|
|
55
|
+
private validateDeno;
|
|
56
|
+
/**
|
|
57
|
+
* Execute TypeScript/JavaScript code in Deno sandbox
|
|
58
|
+
*
|
|
59
|
+
* @param code - Code to execute
|
|
60
|
+
* @param options - Execution options
|
|
61
|
+
* @returns Execution result
|
|
62
|
+
*/
|
|
63
|
+
executeCode(code: string, options?: CodeExecutionOptions): Promise<CodeExecutionResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Create a context bridge file that provides API access to Deno subprocess
|
|
66
|
+
*
|
|
67
|
+
* NOTE: This is a simplified version. Full implementation would need
|
|
68
|
+
* a proper IPC bridge or HTTP server for the Deno subprocess to call back to.
|
|
69
|
+
*/
|
|
70
|
+
private createContextBridge;
|
|
71
|
+
/**
|
|
72
|
+
* Wrap user code with context initialization and result handling
|
|
73
|
+
*/
|
|
74
|
+
private wrapCode;
|
|
75
|
+
/**
|
|
76
|
+
* Run Deno with the script file
|
|
77
|
+
*/
|
|
78
|
+
private runDeno;
|
|
79
|
+
/**
|
|
80
|
+
* List available functions in the filesystem API
|
|
81
|
+
*/
|
|
82
|
+
listAvailableFunctions(): Promise<Record<string, string[]>>;
|
|
83
|
+
/**
|
|
84
|
+
* Get example usage for code execution
|
|
85
|
+
*/
|
|
86
|
+
getExampleUsage(): string;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=code-execution-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-execution-service.d.ts","sourceRoot":"","sources":["../../src/services/code-execution-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAM9D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAYD;;GAEG;AACH,qBAAa,oBAAoB;IAM7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAN/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,aAAa,CAAkB;gBAGpB,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE,YAAY;IA0B7C;;OAEG;YACW,YAAY;IAa1B;;;;;;OAMG;IACG,WAAW,CACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC;IAsD/B;;;;;OAKG;YACW,mBAAmB;IA4BjC;;OAEG;IACH,OAAO,CAAC,QAAQ;IA2ChB;;OAEG;YACW,OAAO;IA2GrB;;OAEG;IACG,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAyBjE;;OAEG;IACH,eAAe,IAAI,MAAM;CAwB1B"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Code Execution Service
|
|
3
|
+
*
|
|
4
|
+
* This service handles code execution in a sandboxed Deno environment.
|
|
5
|
+
* It provides 60-95% token reduction for complex multi-step operations
|
|
6
|
+
* by processing data in the execution environment instead of passing
|
|
7
|
+
* it through the model context.
|
|
8
|
+
*
|
|
9
|
+
* SECURITY: Uses strict Deno permissions and path validation.
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'child_process';
|
|
12
|
+
import * as fs from 'fs/promises';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import * as os from 'os';
|
|
15
|
+
/**
|
|
16
|
+
* Maximum result size in bytes (1MB)
|
|
17
|
+
*/
|
|
18
|
+
const MAX_RESULT_SIZE = 1024 * 1024;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum execution time in milliseconds
|
|
21
|
+
*/
|
|
22
|
+
const MAX_TIMEOUT = 60000;
|
|
23
|
+
/**
|
|
24
|
+
* Service class for handling code execution in Deno sandbox
|
|
25
|
+
*/
|
|
26
|
+
export class CodeExecutionService {
|
|
27
|
+
apiClient;
|
|
28
|
+
cacheManager;
|
|
29
|
+
denoPath;
|
|
30
|
+
mcpServersPath;
|
|
31
|
+
denoValidated = false;
|
|
32
|
+
constructor(apiClient, cacheManager) {
|
|
33
|
+
this.apiClient = apiClient;
|
|
34
|
+
this.cacheManager = cacheManager;
|
|
35
|
+
// Validate and resolve Deno path
|
|
36
|
+
// NOTE: Deno path comes from environment variable or hardcoded default (not user input)
|
|
37
|
+
// This provides defense-in-depth even though path is not user-controlled
|
|
38
|
+
const envDenoPath = process.env.DENO_PATH || '/root/.deno/bin/deno';
|
|
39
|
+
// Validate BEFORE resolution to catch path traversal attempts
|
|
40
|
+
if (envDenoPath.includes('..') || envDenoPath.includes('~')) {
|
|
41
|
+
throw new Error('Invalid Deno path: contains unsafe characters');
|
|
42
|
+
}
|
|
43
|
+
this.denoPath = path.resolve(envDenoPath);
|
|
44
|
+
// Validate and resolve mcp-servers path
|
|
45
|
+
// This path is constructed from cwd (not user input) but we validate to ensure
|
|
46
|
+
// it stays within the project directory for defense-in-depth
|
|
47
|
+
const cwd = process.cwd();
|
|
48
|
+
this.mcpServersPath = path.resolve(path.join(cwd, 'mcp-servers', 'podio'));
|
|
49
|
+
// Verify the resolved path is within project directory (canonical path check)
|
|
50
|
+
if (!this.mcpServersPath.startsWith(cwd)) {
|
|
51
|
+
throw new Error('Invalid mcp-servers path: outside project directory');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate that Deno is installed and accessible
|
|
56
|
+
*/
|
|
57
|
+
async validateDeno() {
|
|
58
|
+
if (this.denoValidated)
|
|
59
|
+
return;
|
|
60
|
+
try {
|
|
61
|
+
await fs.access(this.denoPath, fs.constants.X_OK);
|
|
62
|
+
this.denoValidated = true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
throw new Error(`Deno not found at ${this.denoPath}. Install Deno or set DENO_PATH environment variable.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Execute TypeScript/JavaScript code in Deno sandbox
|
|
70
|
+
*
|
|
71
|
+
* @param code - Code to execute
|
|
72
|
+
* @param options - Execution options
|
|
73
|
+
* @returns Execution result
|
|
74
|
+
*/
|
|
75
|
+
async executeCode(code, options = {}) {
|
|
76
|
+
const startTime = Date.now();
|
|
77
|
+
const timeout = Math.min(options.timeout || 30000, MAX_TIMEOUT);
|
|
78
|
+
try {
|
|
79
|
+
// Validate Deno is installed
|
|
80
|
+
await this.validateDeno();
|
|
81
|
+
// Create temporary file for the code
|
|
82
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'podio-exec-'));
|
|
83
|
+
const codeFile = path.join(tempDir, 'script.ts');
|
|
84
|
+
// Create context bridge file with serialized auth
|
|
85
|
+
const contextFile = path.join(tempDir, 'context-bridge.ts');
|
|
86
|
+
await this.createContextBridge(contextFile);
|
|
87
|
+
// Wrap code with context initialization and result handling
|
|
88
|
+
const wrappedCode = this.wrapCode(code, options.context, contextFile);
|
|
89
|
+
// Write code to temp file
|
|
90
|
+
await fs.writeFile(codeFile, wrappedCode, 'utf-8');
|
|
91
|
+
try {
|
|
92
|
+
// Execute with Deno
|
|
93
|
+
const result = await this.runDeno(codeFile, tempDir, timeout);
|
|
94
|
+
// Validate result size
|
|
95
|
+
const resultJson = JSON.stringify(result.result);
|
|
96
|
+
if (resultJson.length > MAX_RESULT_SIZE) {
|
|
97
|
+
throw new Error(`Result too large: ${resultJson.length} bytes (max ${MAX_RESULT_SIZE})`);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
success: true,
|
|
101
|
+
result: result.result,
|
|
102
|
+
executionTime: Date.now() - startTime,
|
|
103
|
+
stdout: result.stdout,
|
|
104
|
+
stderr: result.stderr,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
// Cleanup temp files
|
|
109
|
+
await fs.rm(tempDir, { recursive: true, force: true }).catch(() => {
|
|
110
|
+
// Ignore cleanup errors
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: error.message || String(error),
|
|
118
|
+
executionTime: Date.now() - startTime,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a context bridge file that provides API access to Deno subprocess
|
|
124
|
+
*
|
|
125
|
+
* NOTE: This is a simplified version. Full implementation would need
|
|
126
|
+
* a proper IPC bridge or HTTP server for the Deno subprocess to call back to.
|
|
127
|
+
*/
|
|
128
|
+
async createContextBridge(contextFile) {
|
|
129
|
+
// For now, we create a stub that logs a warning
|
|
130
|
+
// Full implementation would serialize auth tokens and create new API client
|
|
131
|
+
const bridgeCode = `
|
|
132
|
+
/**
|
|
133
|
+
* Context Bridge for Code Execution
|
|
134
|
+
*
|
|
135
|
+
* WARNING: Full API access not yet implemented.
|
|
136
|
+
* This is a placeholder for Phase 1.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
export function getApiClient() {
|
|
140
|
+
throw new Error('API client access not yet implemented in code execution. Use direct API calls for now.');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getCacheManager() {
|
|
144
|
+
throw new Error('Cache manager access not yet implemented in code execution.');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function initializeContext() {
|
|
148
|
+
// No-op for now
|
|
149
|
+
console.log('Context initialization placeholder');
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
await fs.writeFile(contextFile, bridgeCode, 'utf-8');
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Wrap user code with context initialization and result handling
|
|
156
|
+
*/
|
|
157
|
+
wrapCode(code, context, contextBridgePath) {
|
|
158
|
+
const contextJson = JSON.stringify(context || {});
|
|
159
|
+
return `
|
|
160
|
+
// Auto-generated wrapper for Podio MCP code execution
|
|
161
|
+
|
|
162
|
+
// User-provided context
|
|
163
|
+
const context = ${contextJson};
|
|
164
|
+
|
|
165
|
+
// Import context bridge (placeholder for now)
|
|
166
|
+
// import { initializeContext } from '${contextBridgePath}';
|
|
167
|
+
|
|
168
|
+
// User code starts here
|
|
169
|
+
async function __userMain() {
|
|
170
|
+
${code}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Execute and output result
|
|
174
|
+
(async () => {
|
|
175
|
+
try {
|
|
176
|
+
const result = await __userMain();
|
|
177
|
+
|
|
178
|
+
// Output result as JSON for parsing
|
|
179
|
+
console.log('__RESULT_START__');
|
|
180
|
+
console.log(JSON.stringify(result, null, 2));
|
|
181
|
+
console.log('__RESULT_END__');
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error('__ERROR_START__');
|
|
184
|
+
console.error(error.message || String(error));
|
|
185
|
+
if (error.stack) {
|
|
186
|
+
console.error(error.stack);
|
|
187
|
+
}
|
|
188
|
+
console.error('__ERROR_END__');
|
|
189
|
+
Deno.exit(1);
|
|
190
|
+
}
|
|
191
|
+
})();
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Run Deno with the script file
|
|
196
|
+
*/
|
|
197
|
+
async runDeno(codeFile, tempDir, timeout) {
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
let stdout = '';
|
|
200
|
+
let stderr = '';
|
|
201
|
+
let timedOut = false;
|
|
202
|
+
// Spawn Deno process with strict security restrictions
|
|
203
|
+
const denoProcess = spawn(this.denoPath, [
|
|
204
|
+
'run',
|
|
205
|
+
'--allow-read=' + path.resolve(this.mcpServersPath) + ',' + path.resolve(tempDir), // Only read mcp-servers and temp dir
|
|
206
|
+
'--allow-net=api.podio.com', // Only Podio API
|
|
207
|
+
'--no-prompt', // Fail instead of prompting for permissions
|
|
208
|
+
codeFile,
|
|
209
|
+
], {
|
|
210
|
+
env: {
|
|
211
|
+
...process.env,
|
|
212
|
+
NO_COLOR: '1', // Disable color output for easier parsing
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
// Manual timeout implementation (spawn doesn't have timeout option)
|
|
216
|
+
const timeoutHandle = setTimeout(() => {
|
|
217
|
+
timedOut = true;
|
|
218
|
+
denoProcess.kill('SIGKILL');
|
|
219
|
+
}, timeout);
|
|
220
|
+
// Collect output
|
|
221
|
+
denoProcess.stdout?.on('data', (data) => {
|
|
222
|
+
const chunk = data.toString();
|
|
223
|
+
stdout += chunk;
|
|
224
|
+
// Safety check for output size
|
|
225
|
+
if (stdout.length > MAX_RESULT_SIZE * 2) {
|
|
226
|
+
denoProcess.kill('SIGKILL');
|
|
227
|
+
reject(new Error('Output size exceeded limit'));
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
denoProcess.stderr?.on('data', (data) => {
|
|
231
|
+
const chunk = data.toString();
|
|
232
|
+
stderr += chunk;
|
|
233
|
+
// Safety check for error output size
|
|
234
|
+
if (stderr.length > MAX_RESULT_SIZE) {
|
|
235
|
+
denoProcess.kill('SIGKILL');
|
|
236
|
+
reject(new Error('Error output size exceeded limit'));
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
// Handle completion
|
|
240
|
+
denoProcess.on('close', (code) => {
|
|
241
|
+
clearTimeout(timeoutHandle);
|
|
242
|
+
if (timedOut) {
|
|
243
|
+
reject(new Error(`Code execution timed out after ${timeout}ms`));
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (code !== 0 && code !== null) {
|
|
247
|
+
// Check for error marker
|
|
248
|
+
const errorMatch = stderr.match(/__ERROR_START__\n([\s\S]*?)\n__ERROR_END__/);
|
|
249
|
+
if (errorMatch) {
|
|
250
|
+
reject(new Error(errorMatch[1]));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
reject(new Error(stderr || `Process exited with code ${code}`));
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
// Parse result from stdout
|
|
258
|
+
const resultMatch = stdout.match(/__RESULT_START__\n([\s\S]*?)\n__RESULT_END__/);
|
|
259
|
+
if (resultMatch) {
|
|
260
|
+
try {
|
|
261
|
+
const result = JSON.parse(resultMatch[1]);
|
|
262
|
+
resolve({
|
|
263
|
+
result,
|
|
264
|
+
stdout: stdout.replace(/__RESULT_START__[\s\S]*?__RESULT_END__/, '').trim(),
|
|
265
|
+
stderr: stderr.trim(),
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
catch (parseError) {
|
|
269
|
+
reject(new Error(`Failed to parse result: ${parseError}`));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
// No result marker, return stdout as string
|
|
274
|
+
resolve({
|
|
275
|
+
result: stdout.trim(),
|
|
276
|
+
stdout: '',
|
|
277
|
+
stderr: stderr.trim(),
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
denoProcess.on('error', (error) => {
|
|
282
|
+
clearTimeout(timeoutHandle);
|
|
283
|
+
reject(new Error(`Failed to spawn Deno: ${error.message}`));
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* List available functions in the filesystem API
|
|
289
|
+
*/
|
|
290
|
+
async listAvailableFunctions() {
|
|
291
|
+
return {
|
|
292
|
+
note: [
|
|
293
|
+
'Full filesystem API integration coming in Phase 2',
|
|
294
|
+
'For now, write standalone code that returns JSON results',
|
|
295
|
+
],
|
|
296
|
+
examples: [
|
|
297
|
+
'return { message: "Hello from Deno!" }',
|
|
298
|
+
'return { timestamp: new Date().toISOString() }',
|
|
299
|
+
'const data = [1,2,3]; return { sum: data.reduce((a,b) => a+b, 0) }',
|
|
300
|
+
],
|
|
301
|
+
'future-projects': [
|
|
302
|
+
'listProjects(appId, options?)',
|
|
303
|
+
'filterProjectsByTitle(projects, searchTerm)',
|
|
304
|
+
'findProjectByTitle(projects, title)',
|
|
305
|
+
],
|
|
306
|
+
'future-epics': [
|
|
307
|
+
'listEpics(appId, options?)',
|
|
308
|
+
'filterEpicsByTitle(epics, searchTerm)',
|
|
309
|
+
'findEpicByTitle(epics, title)',
|
|
310
|
+
],
|
|
311
|
+
'future-workflows': ['createItemWithReferences(params)', 'batchCreateWithReferences(items)'],
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get example usage for code execution
|
|
316
|
+
*/
|
|
317
|
+
getExampleUsage() {
|
|
318
|
+
return `
|
|
319
|
+
// Example 1: Simple computation
|
|
320
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
321
|
+
const sum = numbers.reduce((a, b) => a + b, 0);
|
|
322
|
+
return { sum, average: sum / numbers.length };
|
|
323
|
+
|
|
324
|
+
// Example 2: Data transformation
|
|
325
|
+
const data = context.items || [];
|
|
326
|
+
const processed = data
|
|
327
|
+
.filter(item => item.status === 'active')
|
|
328
|
+
.map(item => ({ id: item.id, name: item.name }));
|
|
329
|
+
return { count: processed.length, items: processed };
|
|
330
|
+
|
|
331
|
+
// Example 3: Async operations
|
|
332
|
+
async function fetchData() {
|
|
333
|
+
// Note: API access coming in Phase 2
|
|
334
|
+
return { timestamp: new Date().toISOString() };
|
|
335
|
+
}
|
|
336
|
+
return await fetchData();
|
|
337
|
+
|
|
338
|
+
// NOTE: Filesystem API imports (mcp-servers/podio/) coming in Phase 2
|
|
339
|
+
`.trim();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=code-execution-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-execution-service.js","sourceRoot":"","sources":["../../src/services/code-execution-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAmCzB;;GAEG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpC;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ACjB,+BAA+B;gBAC/B,6CAA6C;gBAC7C,qCAAqC;aACtC;YACD,cAAc,EAAE;gBACd,4BAA4B;gBAC5B,uCAAuC;gBACvC,+BAA+B;aAChC;YACD,kBAAkB,EAAE,CAAC,kCAAkC,EAAE,kCAAkC,CAAC;SAC7F,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO;;;;;;;;;;;;;;;;;;;;;CAqBV,CAAC,IAAI,EAAE,CAAC;IACP,CAAC;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Comment Service
|
|
3
|
+
*
|
|
4
|
+
* This service handles all comment-related operations including CRUD operations
|
|
5
|
+
* for comments on Podio items and other objects.
|
|
6
|
+
*/
|
|
7
|
+
import type { PodioApiClient } from '../api/podio-api-client.js';
|
|
8
|
+
import type { CacheManager } from '../cache/cache-manager.js';
|
|
9
|
+
import type { PodioComment } from '../types/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Service class for handling comment operations.
|
|
12
|
+
*
|
|
13
|
+
* This class encapsulates all comment-related business logic and coordinates
|
|
14
|
+
* between the API client and cache manager. Comments can be on items, tasks,
|
|
15
|
+
* or other Podio objects.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CommentService {
|
|
18
|
+
private readonly apiClient;
|
|
19
|
+
private readonly cacheManager;
|
|
20
|
+
constructor(apiClient: PodioApiClient, cacheManager: CacheManager);
|
|
21
|
+
/**
|
|
22
|
+
* Get all comments for a specific item
|
|
23
|
+
*
|
|
24
|
+
* @param itemId - ID of the item to get comments for
|
|
25
|
+
* @returns Array of comments on the item
|
|
26
|
+
*/
|
|
27
|
+
listItemComments(itemId: number): Promise<PodioComment[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new comment on an item
|
|
30
|
+
*
|
|
31
|
+
* @param itemId - ID of the item to comment on
|
|
32
|
+
* @param text - Text content of the comment
|
|
33
|
+
* @returns Created comment
|
|
34
|
+
*/
|
|
35
|
+
createItemComment(itemId: number, text: string): Promise<PodioComment>;
|
|
36
|
+
/**
|
|
37
|
+
* Get details of a specific comment
|
|
38
|
+
*
|
|
39
|
+
* @param commentId - ID of the comment to get
|
|
40
|
+
* @returns Comment details
|
|
41
|
+
*/
|
|
42
|
+
getComment(commentId: number): Promise<PodioComment>;
|
|
43
|
+
/**
|
|
44
|
+
* Update an existing comment
|
|
45
|
+
*
|
|
46
|
+
* @param commentId - ID of the comment to update
|
|
47
|
+
* @param text - New text content for the comment
|
|
48
|
+
* @returns Updated comment
|
|
49
|
+
*/
|
|
50
|
+
updateComment(commentId: number, text: string): Promise<PodioComment>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete a comment
|
|
53
|
+
*
|
|
54
|
+
* @param commentId - ID of the comment to delete
|
|
55
|
+
*/
|
|
56
|
+
deleteComment(commentId: number): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Get comment revisions (if supported by Podio API)
|
|
59
|
+
* Note: This method is prepared for future use if Podio adds comment revision support
|
|
60
|
+
*
|
|
61
|
+
* @param commentId - ID of the comment to get revisions for
|
|
62
|
+
* @returns Array of comment revisions (placeholder for future implementation)
|
|
63
|
+
*/
|
|
64
|
+
getCommentRevisions(commentId: number): Promise<any[]>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=comment-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-service.d.ts","sourceRoot":"","sources":["../../src/services/comment-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;;GAMG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE,YAAY;IAG7C;;;;;OAKG;IACG,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAY/D;;;;;;OAMG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAiB5E;;;;;OAKG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAY1D;;;;;;OAMG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAiB3E;;;;OAIG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD;;;;;;OAMG;IACG,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CAe7D"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Comment Service
|
|
3
|
+
*
|
|
4
|
+
* This service handles all comment-related operations including CRUD operations
|
|
5
|
+
* for comments on Podio items and other objects.
|
|
6
|
+
*/
|
|
7
|
+
import { PodioValidationError, PodioErrorFactory } from '../errors/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Service class for handling comment operations.
|
|
10
|
+
*
|
|
11
|
+
* This class encapsulates all comment-related business logic and coordinates
|
|
12
|
+
* between the API client and cache manager. Comments can be on items, tasks,
|
|
13
|
+
* or other Podio objects.
|
|
14
|
+
*/
|
|
15
|
+
export class CommentService {
|
|
16
|
+
apiClient;
|
|
17
|
+
cacheManager;
|
|
18
|
+
constructor(apiClient, cacheManager) {
|
|
19
|
+
this.apiClient = apiClient;
|
|
20
|
+
this.cacheManager = cacheManager;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all comments for a specific item
|
|
24
|
+
*
|
|
25
|
+
* @param itemId - ID of the item to get comments for
|
|
26
|
+
* @returns Array of comments on the item
|
|
27
|
+
*/
|
|
28
|
+
async listItemComments(itemId) {
|
|
29
|
+
if (!itemId || itemId <= 0) {
|
|
30
|
+
throw PodioValidationError.requiredField('item_id', 'list item comments');
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return await this.apiClient.getItemComments(itemId);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw PodioErrorFactory.apiCallFailed('list item comments', error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a new comment on an item
|
|
41
|
+
*
|
|
42
|
+
* @param itemId - ID of the item to comment on
|
|
43
|
+
* @param text - Text content of the comment
|
|
44
|
+
* @returns Created comment
|
|
45
|
+
*/
|
|
46
|
+
async createItemComment(itemId, text) {
|
|
47
|
+
if (!itemId || itemId <= 0) {
|
|
48
|
+
throw PodioValidationError.requiredField('item_id', 'create item comment');
|
|
49
|
+
}
|
|
50
|
+
if (!text || typeof text !== 'string' || text.trim().length === 0) {
|
|
51
|
+
throw PodioValidationError.requiredField('text', 'create item comment');
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const trimmedText = text.trim();
|
|
55
|
+
return await this.apiClient.createItemComment(itemId, trimmedText);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw PodioErrorFactory.apiCallFailed('create item comment', error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get details of a specific comment
|
|
63
|
+
*
|
|
64
|
+
* @param commentId - ID of the comment to get
|
|
65
|
+
* @returns Comment details
|
|
66
|
+
*/
|
|
67
|
+
async getComment(commentId) {
|
|
68
|
+
if (!commentId || commentId <= 0) {
|
|
69
|
+
throw PodioValidationError.requiredField('comment_id', 'get comment');
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return await this.apiClient.getComment(commentId);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw PodioErrorFactory.apiCallFailed('get comment', error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Update an existing comment
|
|
80
|
+
*
|
|
81
|
+
* @param commentId - ID of the comment to update
|
|
82
|
+
* @param text - New text content for the comment
|
|
83
|
+
* @returns Updated comment
|
|
84
|
+
*/
|
|
85
|
+
async updateComment(commentId, text) {
|
|
86
|
+
if (!commentId || commentId <= 0) {
|
|
87
|
+
throw PodioValidationError.requiredField('comment_id', 'update comment');
|
|
88
|
+
}
|
|
89
|
+
if (!text || typeof text !== 'string' || text.trim().length === 0) {
|
|
90
|
+
throw PodioValidationError.requiredField('text', 'update comment');
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const trimmedText = text.trim();
|
|
94
|
+
return await this.apiClient.updateComment(commentId, trimmedText);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw PodioErrorFactory.apiCallFailed('update comment', error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Delete a comment
|
|
102
|
+
*
|
|
103
|
+
* @param commentId - ID of the comment to delete
|
|
104
|
+
*/
|
|
105
|
+
async deleteComment(commentId) {
|
|
106
|
+
if (!commentId || commentId <= 0) {
|
|
107
|
+
throw PodioValidationError.requiredField('comment_id', 'delete comment');
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
await this.apiClient.deleteComment(commentId);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw PodioErrorFactory.apiCallFailed('delete comment', error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get comment revisions (if supported by Podio API)
|
|
118
|
+
* Note: This method is prepared for future use if Podio adds comment revision support
|
|
119
|
+
*
|
|
120
|
+
* @param commentId - ID of the comment to get revisions for
|
|
121
|
+
* @returns Array of comment revisions (placeholder for future implementation)
|
|
122
|
+
*/
|
|
123
|
+
async getCommentRevisions(commentId) {
|
|
124
|
+
if (!commentId || commentId <= 0) {
|
|
125
|
+
throw PodioValidationError.requiredField('comment_id', 'get comment revisions');
|
|
126
|
+
}
|
|
127
|
+
// Note: This endpoint may not exist in current Podio API
|
|
128
|
+
// Including as placeholder for potential future support
|
|
129
|
+
try {
|
|
130
|
+
const response = await this.apiClient.get(`/comment/${commentId}/revision/`);
|
|
131
|
+
return response.data;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
// If endpoint doesn't exist, return empty array
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=comment-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-service.js","sourceRoot":"","sources":["../../src/services/comment-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAEN;IACA;IAFnB,YACmB,SAAyB,EACzB,YAA0B;QAD1B,cAAS,GAAT,SAAS,CAAgB;QACzB,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,gBAAgB,CAAC,MAAc;QACnC,IAAI,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,oBAAoB,CAAC,aAAa,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC5E,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,iBAAiB,CAAC,aAAa,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QACrE,CA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