@jk3labs/paperclip-plugin-file-browser 0.2.4 → 0.2.6

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/package.json CHANGED
@@ -1,34 +1,48 @@
1
- {
2
- "name": "@jk3labs/paperclip-plugin-file-browser",
3
- "version": "0.2.4",
4
- "description": "A Paperclip plugin for browsing files in the workspace",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "jest",
8
- "test:watch": "jest --watch"
9
- },
10
- "keywords": [
11
- "paperclip",
12
- "plugin",
13
- "file-browser"
14
- ],
15
- "author": "JKL",
16
- "license": "ISC",
17
- "dependencies": {
18
- "@types/archiver": "^7.0.0",
19
- "archiver": "^8.0.0",
20
- "express": "^4.18.2",
21
- "fs-extra": "^11.1.1"
22
- },
23
- "devDependencies": {
24
- "@types/express": "^5.0.6",
25
- "@types/fs-extra": "^11.0.4",
26
- "@types/jest": "^30.0.0",
27
- "@types/node": "^25.9.1",
28
- "@types/supertest": "^7.2.0",
29
- "jest": "^30.4.2",
30
- "supertest": "^7.2.2",
31
- "ts-jest": "^29.4.11",
32
- "typescript": "^6.0.3"
33
- }
34
- }
1
+ {
2
+ "name": "@jk3labs/paperclip-plugin-file-browser",
3
+ "version": "0.2.6",
4
+ "type": "module",
5
+ "description": "A file browser plugin for Paperclip workspaces",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "scripts": {
13
+ "build": "node ./esbuild.config.mjs",
14
+ "build:rollup": "rollup -c",
15
+ "dev": "node ./esbuild.config.mjs --watch",
16
+ "dev:ui": "paperclip-plugin-dev-server --root . --ui-dir dist/ui --port 4177",
17
+ "test": "vitest run --config ./vitest.config.ts",
18
+ "typecheck": "tsc --noEmit"
19
+ },
20
+ "paperclipPlugin": {
21
+ "manifest": "./dist/manifest.js",
22
+ "worker": "./dist/worker.js",
23
+ "ui": "./dist/ui/"
24
+ },
25
+ "keywords": [
26
+ "paperclip",
27
+ "plugin",
28
+ "workspace"
29
+ ],
30
+ "author": "JK3Labs",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "react": "^18.2.0",
34
+ "react-dom": "^18.2.0"
35
+ },
36
+ "devDependencies": {
37
+ "@paperclipai/plugin-sdk": "2026.525.0",
38
+ "@rollup/plugin-node-resolve": "^16.0.1",
39
+ "@rollup/plugin-typescript": "^12.1.2",
40
+ "@types/node": "^24.6.0",
41
+ "@types/react": "^19.0.8",
42
+ "esbuild": "^0.27.3",
43
+ "rollup": "^4.38.0",
44
+ "tslib": "^2.8.1",
45
+ "typescript": "^5.7.3",
46
+ "vitest": "^3.0.5"
47
+ }
48
+ }
Binary file
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const express_1 = __importDefault(require("express"));
7
- const supertest_1 = __importDefault(require("supertest"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- jest.mock('archiver', () => {
11
- return jest.fn().mockImplementation(() => {
12
- const { PassThrough } = require('stream');
13
- const stream = new PassThrough();
14
- setTimeout(() => { stream.end(); }, 50);
15
- return {
16
- pipe: (dest) => { stream.pipe(dest); return dest; },
17
- directory: () => { },
18
- finalize: jest.fn().mockResolvedValue(undefined),
19
- };
20
- });
21
- });
22
- const index_1 = __importDefault(require("../index"));
23
- const mockRootDir = path_1.default.join(__dirname, 'mock-root');
24
- function createApp() {
25
- const app = (0, express_1.default)();
26
- const routers = [];
27
- const context = {
28
- addRouter: (basePath, router) => {
29
- routers.push({ basePath, router });
30
- },
31
- environment: {
32
- rootDir: mockRootDir,
33
- },
34
- };
35
- index_1.default.register(context);
36
- for (const { basePath, router } of routers) {
37
- app.use(basePath, router);
38
- }
39
- return app;
40
- }
41
- describe('File Browser Plugin', () => {
42
- let app;
43
- const mockFilePath = path_1.default.join(mockRootDir, 'test.txt');
44
- const mockDirPath = path_1.default.join(mockRootDir, 'test-dir');
45
- const mockNestedFilePath = path_1.default.join(mockDirPath, 'nested.txt');
46
- beforeAll(async () => {
47
- await fs_extra_1.default.ensureDir(mockRootDir);
48
- await fs_extra_1.default.writeFile(mockFilePath, 'test content');
49
- await fs_extra_1.default.ensureDir(mockDirPath);
50
- await fs_extra_1.default.writeFile(mockNestedFilePath, 'nested content');
51
- app = createApp();
52
- });
53
- afterAll(async () => {
54
- await fs_extra_1.default.remove(mockRootDir);
55
- });
56
- describe('Plugin registration', () => {
57
- it('should throw if rootDir is invalid', () => {
58
- const badContext = {
59
- addRouter: () => { },
60
- environment: { rootDir: '/nonexistent/path/that/does/not/exist' },
61
- };
62
- expect(() => index_1.default.register(badContext)).toThrow('Invalid root directory');
63
- });
64
- it('should register a router on /files', () => {
65
- const registeredPaths = [];
66
- const ctx = {
67
- addRouter: (basePath) => { registeredPaths.push(basePath); },
68
- environment: { rootDir: mockRootDir },
69
- };
70
- index_1.default.register(ctx);
71
- expect(registeredPaths).toContain('/files');
72
- });
73
- });
74
- describe('GET /files/list', () => {
75
- it('should list files and directories in root', async () => {
76
- const response = await (0, supertest_1.default)(app).get('/files/list');
77
- expect(response.status).toBe(200);
78
- expect(response.body.files).toContain('test.txt');
79
- expect(response.body.directories).toContain('test-dir');
80
- expect(response.body.currentPath).toBe('');
81
- });
82
- it('should list files and directories in subdirectory', async () => {
83
- const response = await (0, supertest_1.default)(app).get('/files/list?path=test-dir');
84
- expect(response.status).toBe(200);
85
- expect(response.body.files).toContain('nested.txt');
86
- expect(response.body.directories).toEqual([]);
87
- });
88
- it('should return 404 for non-existent directory', async () => {
89
- const response = await (0, supertest_1.default)(app).get('/files/list?path=non-existent');
90
- expect(response.status).toBe(404);
91
- });
92
- it('should return 403 for path traversal attempt', async () => {
93
- const response = await (0, supertest_1.default)(app).get('/files/list?path=../../../etc');
94
- expect(response.status).toBe(403);
95
- });
96
- });
97
- describe('GET /files/download', () => {
98
- it('should download a file', async () => {
99
- const response = await (0, supertest_1.default)(app).get('/files/download?path=test.txt');
100
- expect(response.status).toBe(200);
101
- expect(response.text).toBe('test content');
102
- });
103
- it('should return 400 when path is missing', async () => {
104
- const response = await (0, supertest_1.default)(app).get('/files/download');
105
- expect(response.status).toBe(400);
106
- expect(response.body.error).toBe('Path parameter is required');
107
- });
108
- it('should return 404 for non-existent file', async () => {
109
- const response = await (0, supertest_1.default)(app).get('/files/download?path=non-existent.txt');
110
- expect(response.status).toBe(404);
111
- });
112
- it('should return 403 for path traversal attempt', async () => {
113
- const response = await (0, supertest_1.default)(app).get('/files/download?path=../../../etc/passwd');
114
- expect(response.status).toBe(403);
115
- });
116
- });
117
- describe('GET /files/zip', () => {
118
- it('should return a zip response for a valid directory', async () => {
119
- const response = await (0, supertest_1.default)(app).get('/files/zip?path=test-dir');
120
- expect(response.status).toBe(200);
121
- });
122
- it('should return 400 when path is missing', async () => {
123
- const response = await (0, supertest_1.default)(app).get('/files/zip');
124
- expect(response.status).toBe(400);
125
- expect(response.body.error).toBe('Path parameter is required');
126
- });
127
- it('should return 404 for non-existent directory', async () => {
128
- const response = await (0, supertest_1.default)(app).get('/files/zip?path=non-existent');
129
- expect(response.status).toBe(404);
130
- });
131
- it('should return 404 when path points to a file', async () => {
132
- const response = await (0, supertest_1.default)(app).get('/files/zip?path=test.txt');
133
- expect(response.status).toBe(404);
134
- });
135
- it('should return 403 for path traversal attempt', async () => {
136
- const response = await (0, supertest_1.default)(app).get('/files/zip?path=../../../etc');
137
- expect(response.status).toBe(403);
138
- });
139
- });
140
- });
package/dist/index.js DELETED
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const express_1 = __importDefault(require("express"));
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const archiver_1 = __importDefault(require("archiver"));
10
- ;
11
- const plugin = {
12
- id: 'file-browser',
13
- name: 'File Browser Plugin',
14
- description: 'A plugin to browse, download, and zip files in the Paperclip workspace.',
15
- register: (context) => {
16
- const router = express_1.default.Router();
17
- const rootDir = context.environment.rootDir;
18
- // Validate rootDir exists
19
- if (!rootDir || !(fs_extra_1.default.existsSync(rootDir))) {
20
- throw new Error(`Invalid root directory: ${rootDir}`);
21
- }
22
- router.get('/list', async (req, res) => {
23
- try {
24
- const relativePath = req.query.path || '';
25
- const targetPath = path_1.default.join(rootDir, relativePath);
26
- // Security: Ensure targetPath is within rootDir
27
- if (!targetPath.startsWith(rootDir)) {
28
- return res.status(403).json({ error: 'Access denied' });
29
- }
30
- const entries = await fs_extra_1.default.readdir(targetPath, { withFileTypes: true });
31
- const files = entries
32
- .filter(dirent => dirent.isFile())
33
- .map(dirent => dirent.name);
34
- const directories = entries
35
- .filter(dirent => dirent.isDirectory())
36
- .map(dirent => dirent.name);
37
- res.json({
38
- files,
39
- directories,
40
- currentPath: path_1.default.relative(rootDir, targetPath),
41
- rootDir
42
- });
43
- }
44
- catch (error) {
45
- const message = error instanceof Error ? error.message : String(error);
46
- const statusCode = error.code === 'ENOENT' ? 404 : 500;
47
- res.status(statusCode).json({ error: message });
48
- }
49
- });
50
- router.get('/download', async (req, res) => {
51
- try {
52
- const relativePath = req.query.path;
53
- if (!relativePath) {
54
- return res.status(400).json({ error: 'Path parameter is required' });
55
- }
56
- const targetPath = path_1.default.join(rootDir, relativePath);
57
- // Security: Ensure targetPath is within rootDir
58
- if (!targetPath.startsWith(rootDir)) {
59
- return res.status(403).json({ error: 'Access denied' });
60
- }
61
- // Check if path exists and is a file
62
- const stats = await fs_extra_1.default.stat(targetPath);
63
- if (!stats.isFile()) {
64
- return res.status(404).json({ error: 'File not found' });
65
- }
66
- // Stream file for download
67
- res.download(targetPath, path_1.default.basename(targetPath));
68
- }
69
- catch (error) {
70
- const message = error instanceof Error ? error.message : String(error);
71
- const statusCode = error.code === 'ENOENT' ? 404 : 500;
72
- res.status(statusCode).json({ error: message });
73
- }
74
- });
75
- router.get('/zip', async (req, res) => {
76
- try {
77
- const relativePath = req.query.path;
78
- if (!relativePath) {
79
- return res.status(400).json({ error: 'Path parameter is required' });
80
- }
81
- const targetPath = path_1.default.join(rootDir, relativePath);
82
- // Security: Ensure targetPath is within rootDir
83
- if (!targetPath.startsWith(rootDir)) {
84
- return res.status(403).json({ error: 'Access denied' });
85
- }
86
- // Check if path exists and is a directory
87
- const stats = await fs_extra_1.default.stat(targetPath);
88
- if (!stats.isDirectory()) {
89
- return res.status(404).json({ error: 'Directory not found' });
90
- }
91
- // Set headers for ZIP download
92
- res.attachment(`${path_1.default.basename(targetPath)}.zip`);
93
- // Create ZIP stream
94
- const archive = (0, archiver_1.default)('zip', {
95
- zlib: { level: 9 } // Maximum compression
96
- });
97
- archive.pipe(res);
98
- archive.directory(targetPath, false);
99
- await archive.finalize();
100
- }
101
- catch (error) {
102
- const message = error instanceof Error ? error.message : String(error);
103
- const statusCode = error.code === 'ENOENT' ? 404 : 500;
104
- res.status(statusCode).json({ error: message });
105
- }
106
- });
107
- context.addRouter('/files', router);
108
- },
109
- };
110
- exports.default = plugin;
package/index.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- const express = require("express");
4
- const fs = require("fs-extra");
5
- const path = require("path");
6
-
7
- module.exports = (pluginContext) => {
8
- const router = express.Router();
9
-
10
- // Dynamic root lookup: Use Paperclip's workspace root
11
- const rootDir = pluginContext.workspaceRoot || process.env.PAPERCLIP_WORKSPACE_ROOT || process.cwd();
12
-
13
- /**
14
- * GET /files/list
15
- * List files and directories at the given path
16
- */
17
- router.get("/list", async (req, res) => {
18
- const { dir } = req.query;
19
- if (!dir) {
20
- return res.status(400).json({ error: "Query parameter 'dir' is required" });
21
- }
22
-
23
- const targetPath = path.join(rootDir, dir);
24
- try {
25
- const stats = await fs.stat(targetPath);
26
- if (!stats.isDirectory()) {
27
- return res.status(400).json({ error: "Path is not a directory" });
28
- }
29
-
30
- const items = await fs.readdir(targetPath);
31
- const detailedItems = await Promise.all(
32
- items.map(async (item) => {
33
- const itemPath = path.join(targetPath, item);
34
- const itemStats = await fs.stat(itemPath);
35
- return {
36
- name: item,
37
- path: path.relative(rootDir, itemPath),
38
- isDirectory: itemStats.isDirectory(),
39
- size: itemStats.size,
40
- modified: itemStats.mtime
41
- };
42
- })
43
- );
44
-
45
- res.json({
46
- path: dir,
47
- items: detailedItems
48
- });
49
- } catch (error) {
50
- res.status(500).json({ error: error.message });
51
- }
52
- });
53
-
54
- /**
55
- * GET /files/read
56
- * Read file content
57
- */
58
- router.get("/read", async (req, res) => {
59
- const { file } = req.query;
60
- if (!file) {
61
- return res.status(400).json({ error: "Query parameter 'file' is required" });
62
- }
63
-
64
- const filePath = path.join(rootDir, file);
65
- try {
66
- const stats = await fs.stat(filePath);
67
- if (!stats.isFile()) {
68
- return res.status(400).json({ error: "Path is not a file" });
69
- }
70
-
71
- const content = await fs.readFile(filePath, "utf-8");
72
- res.json({
73
- path: file,
74
- content
75
- });
76
- } catch (error) {
77
- res.status(500).json({ error: error.message });
78
- }
79
- });
80
-
81
- return router;
82
- };
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- testMatch: ['**/__tests__/**/*.spec.ts'],
5
- moduleFileExtensions: ['ts', 'js', 'json', 'node'],
6
- };
package/manifest.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { PaperclipPluginManifestV1 } from '@paperclipai/shared';
2
-
3
- export const manifest: PaperclipPluginManifestV1 = {
4
- id: 'jkl.file-browser',
5
- apiVersion: 1,
6
- version: '1.0.0',
7
- displayName: 'File Browser',
8
- description: 'A plugin to browse files in the Paperclip workspace.',
9
- author: 'JKL <support@jkl.co>',
10
- categories: ['utilities'],
11
- capabilities: [],
12
- entrypoints: {
13
- worker: 'dist/index.js',
14
- },
15
- };
@@ -1,161 +0,0 @@
1
- import express from 'express';
2
- import request from 'supertest';
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
-
6
- jest.mock('archiver', () => {
7
- return jest.fn().mockImplementation(() => {
8
- const { PassThrough } = require('stream');
9
- const stream = new PassThrough();
10
- setTimeout(() => { stream.end(); }, 50);
11
- return {
12
- pipe: (dest: NodeJS.WritableStream) => { stream.pipe(dest); return dest; },
13
- directory: () => {},
14
- finalize: jest.fn().mockResolvedValue(undefined),
15
- };
16
- });
17
- });
18
-
19
- import plugin from '../index';
20
-
21
- const mockRootDir = path.join(__dirname, 'mock-root');
22
-
23
- function createApp(): express.Express {
24
- const app = express();
25
- const routers: Array<{ basePath: string; router: express.Router }> = [];
26
-
27
- const context = {
28
- addRouter: (basePath: string, router: express.Router) => {
29
- routers.push({ basePath, router });
30
- },
31
- environment: {
32
- rootDir: mockRootDir,
33
- },
34
- };
35
-
36
- plugin.register(context);
37
-
38
- for (const { basePath, router } of routers) {
39
- app.use(basePath, router);
40
- }
41
-
42
- return app;
43
- }
44
-
45
- describe('File Browser Plugin', () => {
46
- let app: express.Express;
47
- const mockFilePath = path.join(mockRootDir, 'test.txt');
48
- const mockDirPath = path.join(mockRootDir, 'test-dir');
49
- const mockNestedFilePath = path.join(mockDirPath, 'nested.txt');
50
-
51
- beforeAll(async () => {
52
- await fs.ensureDir(mockRootDir);
53
- await fs.writeFile(mockFilePath, 'test content');
54
- await fs.ensureDir(mockDirPath);
55
- await fs.writeFile(mockNestedFilePath, 'nested content');
56
- app = createApp();
57
- });
58
-
59
- afterAll(async () => {
60
- await fs.remove(mockRootDir);
61
- });
62
-
63
- describe('Plugin registration', () => {
64
- it('should throw if rootDir is invalid', () => {
65
- const badContext = {
66
- addRouter: () => {},
67
- environment: { rootDir: '/nonexistent/path/that/does/not/exist' },
68
- };
69
- expect(() => plugin.register(badContext)).toThrow('Invalid root directory');
70
- });
71
-
72
- it('should register a router on /files', () => {
73
- const registeredPaths: string[] = [];
74
- const ctx = {
75
- addRouter: (basePath: string) => { registeredPaths.push(basePath); },
76
- environment: { rootDir: mockRootDir },
77
- };
78
- plugin.register(ctx);
79
- expect(registeredPaths).toContain('/files');
80
- });
81
- });
82
-
83
- describe('GET /files/list', () => {
84
- it('should list files and directories in root', async () => {
85
- const response = await request(app).get('/files/list');
86
- expect(response.status).toBe(200);
87
- expect(response.body.files).toContain('test.txt');
88
- expect(response.body.directories).toContain('test-dir');
89
- expect(response.body.currentPath).toBe('');
90
- });
91
-
92
- it('should list files and directories in subdirectory', async () => {
93
- const response = await request(app).get('/files/list?path=test-dir');
94
- expect(response.status).toBe(200);
95
- expect(response.body.files).toContain('nested.txt');
96
- expect(response.body.directories).toEqual([]);
97
- });
98
-
99
- it('should return 404 for non-existent directory', async () => {
100
- const response = await request(app).get('/files/list?path=non-existent');
101
- expect(response.status).toBe(404);
102
- });
103
-
104
- it('should return 403 for path traversal attempt', async () => {
105
- const response = await request(app).get('/files/list?path=../../../etc');
106
- expect(response.status).toBe(403);
107
- });
108
- });
109
-
110
- describe('GET /files/download', () => {
111
- it('should download a file', async () => {
112
- const response = await request(app).get('/files/download?path=test.txt');
113
- expect(response.status).toBe(200);
114
- expect(response.text).toBe('test content');
115
- });
116
-
117
- it('should return 400 when path is missing', async () => {
118
- const response = await request(app).get('/files/download');
119
- expect(response.status).toBe(400);
120
- expect(response.body.error).toBe('Path parameter is required');
121
- });
122
-
123
- it('should return 404 for non-existent file', async () => {
124
- const response = await request(app).get('/files/download?path=non-existent.txt');
125
- expect(response.status).toBe(404);
126
- });
127
-
128
- it('should return 403 for path traversal attempt', async () => {
129
- const response = await request(app).get('/files/download?path=../../../etc/passwd');
130
- expect(response.status).toBe(403);
131
- });
132
- });
133
-
134
- describe('GET /files/zip', () => {
135
- it('should return a zip response for a valid directory', async () => {
136
- const response = await request(app).get('/files/zip?path=test-dir');
137
- expect(response.status).toBe(200);
138
- });
139
-
140
- it('should return 400 when path is missing', async () => {
141
- const response = await request(app).get('/files/zip');
142
- expect(response.status).toBe(400);
143
- expect(response.body.error).toBe('Path parameter is required');
144
- });
145
-
146
- it('should return 404 for non-existent directory', async () => {
147
- const response = await request(app).get('/files/zip?path=non-existent');
148
- expect(response.status).toBe(404);
149
- });
150
-
151
- it('should return 404 when path points to a file', async () => {
152
- const response = await request(app).get('/files/zip?path=test.txt');
153
- expect(response.status).toBe(404);
154
- });
155
-
156
- it('should return 403 for path traversal attempt', async () => {
157
- const response = await request(app).get('/files/zip?path=../../../etc');
158
- expect(response.status).toBe(403);
159
- });
160
- });
161
- });