Skip to content

Commit 115b6a2

Browse files
committed
Merge pull request 'Release/2.0.0' from develop into master
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/docspace-plugin-sdk/pulls/20
2 parents 730c49c + 22749ac commit 115b6a2

File tree

17 files changed

+366
-123
lines changed

17 files changed

+366
-123
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Change Log
22

3+
## 2.0.0
4+
5+
## Changed
6+
7+
- Separate security for file in another enum FilesSecurity
8+
9+
## Added
10+
11+
- Add fileSecurity, security props to IFileItem
12+
- Add withoutBodyPadding and withoutHeaderMargin properties to IModalDialog
13+
- Add updateCreateDialogModal action
14+
- Add isAutoFocusOnError, errorText, onError, onChange, isCloseAfterCreate, isCreateDisabled properties to ICreateDialog
15+
316
## 1.1.1
417

518
## Added

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ You can find a list of all the dialog questions [here](https://github.com/ONLYOF
3232

3333
Code samples are available at [https://github.com/ONLYOFFICE/docspace-plugins](https://github.com/ONLYOFFICE/docspace-plugins).
3434

35+
For plugins created with the old template (SDK 1.1.1), replace the build script in *package.json* with the following:
36+
```json
37+
"build": "webpack && npx build-docspace-plugin"
38+
```
39+
40+
:::note
41+
To ensure the new npx command works correctly, you need to update the globally installed *@onlyoffice/docspace-plugin-sdk* package to version 2.0.0 or higher.
42+
:::
43+
3544
## Building a plugin
3645

3746
To build a plugin, you need the *yarn* package manager to be installed. After that, follow the instructions below:
@@ -54,6 +63,8 @@ yarn install
5463
yarn build
5564
```
5665

57-
This command generates the obfuscated code from the entire project and collects it into the *plugin.js* file using the *webpack* npm package. After that the plugin builder from the [createZip.js](https://github.com/ONLYOFFICE/docspace-plugin-sdk/blob/master/template/scripts/createZip.js) file generates the *config.json* file from the *package.json* data and creates an archive that contains the *assets* folder, the *plugin.js* file, and the *config.json* file.
66+
This command generates the obfuscated code from the entire project and collects it into the *plugin.js* file using the *webpack* npm package.
67+
68+
The *dist* folder will be created in the root plugin folder and the plugin archive will be placed in it. This archive is the completed plugin that can be uploaded to the DocSpace portal.
5869

59-
The *dist* folder will be created in the root plugin folder and the plugin archive will be placed in it. This archive is the completed plugin that can be uploaded to the DocSpace portal.
70+
The old *createZip* script is no longer required and can be safely removed.

npx/buildPlugin.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* (c) Copyright Ascensio System SIA 2025
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import JSZip from "jszip";
20+
import * as fs from "fs";
21+
import * as path from "path";
22+
import { fileURLToPath } from "url";
23+
24+
/**
25+
* Dynamically reads information from the installed SDK package.
26+
* @returns {{minDocSpaceVersion: string}}
27+
*/
28+
function getSdkInfo() {
29+
try {
30+
// Find the package.json of the installed SDK
31+
const sdkPackageUrl = new URL("../package.json", import.meta.url);
32+
const sdkPackagePath = fileURLToPath(sdkPackageUrl);
33+
34+
const sdkPackage = JSON.parse(fs.readFileSync(sdkPackagePath, "utf8"));
35+
36+
const minDocSpaceVersion = sdkPackage.minDocSpaceVersion;
37+
38+
return { minDocSpaceVersion };
39+
} catch (error) {
40+
console.error(
41+
`❌ Error: Could not read information from '@onlyoffice/docspace-plugin-sdk'.`
42+
);
43+
console.error(
44+
" Please make sure the package is installed correctly (`npm install`)."
45+
);
46+
process.exit(1);
47+
}
48+
}
49+
50+
/**
51+
* Builds the plugin zip file from the current directory
52+
*/
53+
async function buildPlugin() {
54+
const currentDir = process.cwd();
55+
56+
// Check if required files exist
57+
const pluginJsPath = path.join(currentDir, "dist", "plugin.js");
58+
const packageJsonPath = path.join(currentDir, "package.json");
59+
60+
if (!fs.existsSync(pluginJsPath)) {
61+
console.error(
62+
"❌ Error: dist/plugin.js not found. Please build your plugin first."
63+
);
64+
process.exit(1);
65+
}
66+
67+
if (!fs.existsSync(packageJsonPath)) {
68+
console.error("❌ Error: package.json not found in current directory.");
69+
process.exit(1);
70+
}
71+
72+
console.log("🔨 Building plugin...");
73+
74+
const zip = new JSZip();
75+
76+
// Read plugin.js
77+
const jsData = fs.readFileSync(pluginJsPath, "utf-8");
78+
79+
// Read package.json
80+
const jsonData = fs.readFileSync(packageJsonPath, "utf-8");
81+
const jsonDataObj = JSON.parse(jsonData);
82+
83+
// Get the latest SDK info directly from the source
84+
const sdkInfo = getSdkInfo();
85+
86+
// Create config.json for the plugin
87+
const docspace = {
88+
name: jsonDataObj.name.toLowerCase(),
89+
version: jsonDataObj.version || DEFAULT_PLUGIN_VERSION,
90+
minDocSpaceVersion: sdkInfo.minDocSpaceVersion || "",
91+
description: jsonDataObj.description || "",
92+
license: jsonDataObj.license || "",
93+
author: jsonDataObj.author || "",
94+
pluginName: jsonDataObj.pluginName || "",
95+
homePage: jsonDataObj.homepage || "",
96+
image: jsonDataObj.logo || "",
97+
scopes: jsonDataObj.scopes ? jsonDataObj.scopes.join(",") : "",
98+
cspDomains: (jsonDataObj.cspDomains && jsonDataObj.cspDomains.join(",")) || "",
99+
};
100+
101+
// Add files to zip
102+
zip.file("plugin.js", jsData);
103+
zip.file("config.json", JSON.stringify(docspace, null, 2));
104+
105+
// Add assets if they exist
106+
const assetsPath = path.join(currentDir, "assets");
107+
if (fs.existsSync(assetsPath)) {
108+
const assetsFiles = fs.readdirSync(assetsPath);
109+
110+
assetsFiles.forEach((file) => {
111+
const filePath = path.join(assetsPath, file);
112+
const data = fs.readFileSync(filePath, "base64");
113+
zip.file(`assets/${file}`, data, { base64: true });
114+
});
115+
116+
console.log(`📁 Added ${assetsFiles.length} asset(s) to plugin`);
117+
}
118+
119+
const distPath = path.join(currentDir, "dist");
120+
// Generate and save the zip file
121+
try {
122+
const content = await zip.generateAsync({ type: "nodebuffer" });
123+
const outputPath = path.join(distPath, "plugin.zip");
124+
fs.writeFileSync(outputPath, content);
125+
126+
console.log(`✅ Plugin built successfully: ${outputPath}`);
127+
console.log(`📦 Plugin name: ${docspace.name}`);
128+
console.log(`🔢 Version: ${docspace.version}`);
129+
console.log(`🎯 Min DocSpace version: ${docspace.minDocSpaceVersion}`);
130+
} catch (error) {
131+
console.error("❌ Error generating plugin zip:", error);
132+
process.exit(1);
133+
}
134+
}
135+
136+
// Run the build process
137+
buildPlugin().catch((error) => {
138+
console.error("❌ Build failed:", error);
139+
process.exit(1);
140+
});

npx/constants/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* (c) Copyright Ascensio System SIA 2025
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export const DEFAULT_PLUGIN_VERSION = "0.0.1";

npx/index.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/usr/bin/env node
22

33
/*
4-
* (c) Copyright Ascensio System SIA 2025
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*/
4+
* (c) Copyright Ascensio System SIA 2025
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
1818

1919
import inquirer from "inquirer";
2020
import * as fs from "fs";
@@ -24,6 +24,7 @@ import { fileURLToPath } from "url";
2424

2525
import createTemplate from "./createTemplate.js";
2626
import QUESTIONS from "./dialog.js";
27+
import { DEFAULT_PLUGIN_VERSION } from "./constants/index.js";
2728

2829
const __filename = fileURLToPath(import.meta.url);
2930

@@ -34,7 +35,7 @@ const TEMPLATE_PATH = path.join(__dirname, "../template");
3435

3536
inquirer.prompt(QUESTIONS).then((answers) => {
3637
const name = answers["plugin-name"];
37-
const version = answers["plugin-version"];
38+
const version = answers["plugin-version"] || DEFAULT_PLUGIN_VERSION;
3839
const author = answers["plugin-author"];
3940
const logo = answers["plugin-logo"];
4041
const description = answers["plugin-description"];

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@onlyoffice/docspace-plugin-sdk",
3-
"version": "1.1.1",
3+
"version": "2.0.0",
4+
"minDocSpaceVersion": "3.5.0",
45
"description": "Simple plugin system for onlyoffice docspace",
56
"license": "Apache-2.0",
67
"homepage": "https://www.onlyoffice.com",
@@ -13,19 +14,21 @@
1314
"url": "git+https://github.com/ONLYOFFICE/docspace-plugin-sdk.git"
1415
},
1516
"bugs": {
16-
"url": "https://github.com/ONLYOFFICE/docspace-plugin-sdk"
17+
"url": "https://github.com/ONLYOFFICE/docspace-plugin-sdk",
18+
"email": "support@onlyoffice.com"
1719
},
1820
"keywords": [
1921
"onlyoffice",
2022
"docspace",
2123
"plugin"
2224
],
23-
"main": "dist/index.js",
24-
"types": "dist/index.d.ts",
25-
"type": "module",
2625
"bin": {
26+
"build-docspace-plugin": "./npx/buildPlugin.js",
2727
"create-docspace-plugin": "./npx/index.js"
2828
},
29+
"main": "dist/index.js",
30+
"types": "dist/index.d.ts",
31+
"type": "module",
2932
"scripts": {
3033
"build": "tsc",
3134
"prepublish": "tsc"
@@ -36,6 +39,7 @@
3639
"typescript": "^5.6.0"
3740
},
3841
"dependencies": {
39-
"inquirer": "^9.1.0"
42+
"inquirer": "^9.1.0",
43+
"jszip": "^3.10.1"
4044
}
4145
}

src/enums/Actions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ export const enum Actions {
7979
*/
8080
showCreateDialogModal = "show-create-dialog-modal",
8181

82+
/**
83+
* Calls a function to update a modal window for creating certain item (file, folder, etc.).
84+
* It does not work if the "createDialogProps" parameter is not passed to the message.
85+
*/
86+
updateCreateDialogModal = "update-create-dialog-modal",
87+
8288
/**
8389
* Calls a function to open a modal window.
8490
* It does not work if the "modalDialogProps" parameter is not passed to the message.

src/enums/Files.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,77 @@ export const enum FilesExst {
142142
/** Extensible Markup Language */
143143
xml = ".xml",
144144
}
145+
146+
/**
147+
* Defines the supported file security parameters.
148+
*/
149+
export const enum FilesSecurity {
150+
/** Permission to convert files to other formats */
151+
Convert = "Convert",
152+
153+
/** Permission to copy files and folders */
154+
Copy = "Copy",
155+
156+
/** Permission to apply custom filters */
157+
CustomFilter = "CustomFilter",
158+
159+
/** Permission to delete items */
160+
Delete = "Delete",
161+
162+
/** Permission to download files */
163+
Download = "Download",
164+
165+
/** Permission to create duplicates of items */
166+
Duplicate = "Duplicate",
167+
168+
/** Permission to edit files */
169+
Edit = "Edit",
170+
171+
/** Permission to view and edit file history */
172+
EditHistory = "EditHistory",
173+
174+
/** Permission to fill forms */
175+
FillForms = "FillForms",
176+
177+
/** Permission to lock/unlock files */
178+
Lock = "Lock",
179+
180+
/** Permission to move items */
181+
Move = "Move",
182+
183+
/** Permission to view and read content */
184+
Read = "Read",
185+
186+
/** Permission to read file history */
187+
ReadHistory = "ReadHistory",
188+
189+
/** Permission to rename items */
190+
Rename = "Rename",
191+
192+
/** Permission to review documents */
193+
Review = "Review",
194+
195+
/** Permission to submit forms to gallery */
196+
SubmitToFormGallery = "SubmitToFormGallery",
197+
198+
/** Permission to stop form filling process */
199+
StopFilling = "StopFilling",
200+
201+
/** Permission to reset form filling */
202+
ResetFilling = "ResetFilling",
203+
204+
/** Permission to edit forms */
205+
EditForm = "EditForm",
206+
207+
/** Permission to comment on files */
208+
Comment = "Comment",
209+
210+
/** Permission to create rooms from existing content */
211+
CreateRoomFrom = "CreateRoomFrom",
212+
213+
/** Permission to copy links to files */
214+
CopyLink = "CopyLink",
215+
216+
/** Permission to embed content */
217+
Embed = "Embed",
218+
}

0 commit comments

Comments
 (0)