@crowdin/app-project-module 0.24.2 → 0.25.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 +18 -18
- package/out/handlers/install.js +15 -2
- package/out/models/index.d.ts +8 -2
- package/out/util/connection.js +15 -2
- package/out/util/defaults.js +35 -3
- package/out/views/main.handlebars +5 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -133,26 +133,26 @@ const configuration = {
|
|
|
133
133
|
const directories = await client.sourceFilesApi
|
|
134
134
|
.withFetchAll()
|
|
135
135
|
.listProjectDirectories(projectId);
|
|
136
|
-
const { folder, files } = await crowdinAppFunctions.getOrCreateFolder(
|
|
137
|
-
directories.data.map((d) => d.data),
|
|
136
|
+
const { folder, files } = await crowdinAppFunctions.getOrCreateFolder({
|
|
137
|
+
directories: directories.data.map((d) => d.data),
|
|
138
138
|
client,
|
|
139
139
|
projectId,
|
|
140
|
-
'Folder from integration',
|
|
141
|
-
rootFolder
|
|
142
|
-
);
|
|
140
|
+
directoryName: 'Folder from integration',
|
|
141
|
+
parentDirectory: rootFolder
|
|
142
|
+
});
|
|
143
143
|
const fileContent = {
|
|
144
144
|
title: 'Hello World',
|
|
145
145
|
};
|
|
146
|
-
await crowdinAppFunctions.updateOrCreateFile(
|
|
146
|
+
await crowdinAppFunctions.updateOrCreateFile({
|
|
147
147
|
client,
|
|
148
148
|
projectId,
|
|
149
|
-
'integration.json',
|
|
150
|
-
'Sample file from integration',
|
|
151
|
-
'json',
|
|
152
|
-
folder.id,
|
|
153
|
-
fileContent,
|
|
154
|
-
files.find((f) => f.name === 'integration.json'),
|
|
155
|
-
);
|
|
149
|
+
name: 'integration.json',
|
|
150
|
+
title: 'Sample file from integration',
|
|
151
|
+
type: 'json',
|
|
152
|
+
directoryId: folder.id,
|
|
153
|
+
data: fileContent,
|
|
154
|
+
file: files.find((f) => f.name === 'integration.json'),
|
|
155
|
+
});
|
|
156
156
|
return {
|
|
157
157
|
message: 'Some message',
|
|
158
158
|
};
|
|
@@ -163,13 +163,13 @@ const configuration = {
|
|
|
163
163
|
const directories = await client.sourceFilesApi
|
|
164
164
|
.withFetchAll()
|
|
165
165
|
.listProjectDirectories(projectId);
|
|
166
|
-
const { files } = await crowdinAppFunctions.getFolder(
|
|
167
|
-
directories.data.map((d) => d.data),
|
|
166
|
+
const { files } = await crowdinAppFunctions.getFolder({
|
|
167
|
+
directories: directories.data.map((d) => d.data),
|
|
168
168
|
client,
|
|
169
169
|
projectId,
|
|
170
|
-
'Folder from integration',
|
|
171
|
-
rootFolder
|
|
172
|
-
);
|
|
170
|
+
directoryName: 'Folder from integration',
|
|
171
|
+
parentDirectory: rootFolder
|
|
172
|
+
});
|
|
173
173
|
const file = files.find((f) => f.name === 'integration.json');
|
|
174
174
|
if (file) {
|
|
175
175
|
const translationsLink =
|
package/out/handlers/install.js
CHANGED
|
@@ -46,14 +46,27 @@ function fetchToken(config, event) {
|
|
|
46
46
|
var _a, _b;
|
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
48
|
if (config.authenticationType === models_1.AuthenticationType.CODE) {
|
|
49
|
-
const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(
|
|
49
|
+
const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)({
|
|
50
|
+
clientId: config.clientId,
|
|
51
|
+
clientSecret: config.clientSecret,
|
|
52
|
+
code: event.code || '',
|
|
53
|
+
url: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl,
|
|
54
|
+
});
|
|
50
55
|
return {
|
|
51
56
|
accessToken: (0, util_1.encryptData)(config, token.accessToken),
|
|
52
57
|
refreshToken: (0, util_1.encryptData)(config, token.refreshToken),
|
|
53
58
|
expiresIn: token.expiresIn,
|
|
54
59
|
};
|
|
55
60
|
}
|
|
56
|
-
const token = yield (0, crowdin_apps_functions_1.fetchAppToken)(
|
|
61
|
+
const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
|
|
62
|
+
appId: config.identifier,
|
|
63
|
+
appSecret: event.appSecret,
|
|
64
|
+
clientId: config.clientId,
|
|
65
|
+
clientSecret: config.clientSecret,
|
|
66
|
+
domain: event.domain || '',
|
|
67
|
+
userId: event.userId,
|
|
68
|
+
url: (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl,
|
|
69
|
+
});
|
|
57
70
|
return {
|
|
58
71
|
accessToken: (0, util_1.encryptData)(config, token.accessToken),
|
|
59
72
|
expiresIn: token.expiresIn,
|
package/out/models/index.d.ts
CHANGED
|
@@ -370,19 +370,25 @@ export interface MessageResult<T> {
|
|
|
370
370
|
message?: string;
|
|
371
371
|
}
|
|
372
372
|
export declare type TreeItem = File | Folder;
|
|
373
|
+
/**
|
|
374
|
+
* 0 - folder
|
|
375
|
+
* 1 - file
|
|
376
|
+
* 2 - branch
|
|
377
|
+
*/
|
|
378
|
+
declare type IntegrationTreeElementType = '0' | '1' | '2';
|
|
373
379
|
export interface File {
|
|
374
380
|
id: string;
|
|
375
381
|
name: string;
|
|
376
382
|
type: SourceFilesModel.FileType;
|
|
377
383
|
parentId?: string;
|
|
378
|
-
nodeType?:
|
|
384
|
+
nodeType?: IntegrationTreeElementType;
|
|
379
385
|
customContent?: string;
|
|
380
386
|
}
|
|
381
387
|
export interface Folder {
|
|
382
388
|
id: string;
|
|
383
389
|
name: string;
|
|
384
390
|
parentId?: string;
|
|
385
|
-
nodeType?:
|
|
391
|
+
nodeType?: IntegrationTreeElementType;
|
|
386
392
|
customContent?: string;
|
|
387
393
|
}
|
|
388
394
|
export interface IntegrationRequest extends CrowdinClientRequest {
|
package/out/util/connection.js
CHANGED
|
@@ -23,14 +23,27 @@ function refreshToken(config, credentials) {
|
|
|
23
23
|
var _a, _b;
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
if (config.authenticationType === models_1.AuthenticationType.CODE) {
|
|
26
|
-
const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)(
|
|
26
|
+
const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)({
|
|
27
|
+
clientId: config.clientId,
|
|
28
|
+
clientSecret: config.clientSecret,
|
|
29
|
+
refreshToken: (0, _1.decryptData)(config, credentials.refreshToken),
|
|
30
|
+
url: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl,
|
|
31
|
+
});
|
|
27
32
|
return {
|
|
28
33
|
accessToken: (0, _1.encryptData)(config, token.accessToken),
|
|
29
34
|
refreshToken: (0, _1.encryptData)(config, token.refreshToken),
|
|
30
35
|
expiresIn: token.expiresIn,
|
|
31
36
|
};
|
|
32
37
|
}
|
|
33
|
-
const token = yield (0, crowdin_apps_functions_1.fetchAppToken)(
|
|
38
|
+
const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
|
|
39
|
+
appId: config.identifier,
|
|
40
|
+
appSecret: credentials.appSecret,
|
|
41
|
+
clientId: config.clientId,
|
|
42
|
+
clientSecret: config.clientSecret,
|
|
43
|
+
domain: credentials.domain || '',
|
|
44
|
+
userId: credentials.userId,
|
|
45
|
+
url: (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl,
|
|
46
|
+
});
|
|
34
47
|
return {
|
|
35
48
|
accessToken: (0, _1.encryptData)(config, token.accessToken),
|
|
36
49
|
expiresIn: token.expiresIn,
|
package/out/util/defaults.js
CHANGED
|
@@ -37,7 +37,12 @@ function getRootFolder(config, integration, client, projectId) {
|
|
|
37
37
|
}
|
|
38
38
|
const folder = integration.appFolderName || config.name;
|
|
39
39
|
const directories = (yield client.sourceFilesApi.withFetchAll().listProjectDirectories(projectId)).data.map((d) => d.data);
|
|
40
|
-
const { folder: rootFolder } = yield crowdinAppFunctions.getOrCreateFolder(
|
|
40
|
+
const { folder: rootFolder } = yield crowdinAppFunctions.getOrCreateFolder({
|
|
41
|
+
directories,
|
|
42
|
+
client,
|
|
43
|
+
projectId,
|
|
44
|
+
directoryName: folder,
|
|
45
|
+
});
|
|
41
46
|
return rootFolder;
|
|
42
47
|
});
|
|
43
48
|
}
|
|
@@ -50,6 +55,7 @@ exports.getOauthRoute = getOauthRoute;
|
|
|
50
55
|
function applyDefaults(config, integration) {
|
|
51
56
|
if (!integration.getCrowdinFiles) {
|
|
52
57
|
integration.getCrowdinFiles = (projectId, client, rootFolder) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const allBranches = (yield client.sourceFilesApi.withFetchAll().listProjectBranches(projectId)).data.map((d) => d.data);
|
|
53
59
|
let allDirectories;
|
|
54
60
|
if (rootFolder) {
|
|
55
61
|
allDirectories = (yield client.sourceFilesApi.withFetchAll().listProjectDirectories(projectId, {
|
|
@@ -67,7 +73,20 @@ function applyDefaults(config, integration) {
|
|
|
67
73
|
(!rootFolder && !f.directoryId));
|
|
68
74
|
const res = [];
|
|
69
75
|
allDirectories.forEach((e) => {
|
|
70
|
-
|
|
76
|
+
let parentId = rootFolder && e.directoryId === rootFolder.id ? undefined : e.directoryId;
|
|
77
|
+
if (!parentId && e.branchId) {
|
|
78
|
+
const branch = allBranches.find((branch) => branch.id === e.branchId);
|
|
79
|
+
if (branch) {
|
|
80
|
+
parentId = branch.id;
|
|
81
|
+
if (!res.find((node) => node.id === branch.id.toString())) {
|
|
82
|
+
res.push({
|
|
83
|
+
id: branch.id.toString(),
|
|
84
|
+
name: branch.name,
|
|
85
|
+
nodeType: '2',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
71
90
|
res.push({
|
|
72
91
|
id: e.id.toString(),
|
|
73
92
|
parentId: parentId ? parentId.toString() : undefined,
|
|
@@ -75,7 +94,20 @@ function applyDefaults(config, integration) {
|
|
|
75
94
|
});
|
|
76
95
|
});
|
|
77
96
|
files.forEach((e) => {
|
|
78
|
-
|
|
97
|
+
let parentId = rootFolder && e.directoryId === rootFolder.id ? undefined : e.directoryId;
|
|
98
|
+
if (!parentId && e.branchId) {
|
|
99
|
+
const branch = allBranches.find((branch) => branch.id === e.branchId);
|
|
100
|
+
if (branch) {
|
|
101
|
+
parentId = branch.id;
|
|
102
|
+
if (!res.find((node) => node.id === branch.id.toString())) {
|
|
103
|
+
res.push({
|
|
104
|
+
id: branch.id.toString(),
|
|
105
|
+
name: branch.name,
|
|
106
|
+
nodeType: '2',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
79
111
|
res.push({
|
|
80
112
|
id: e.id.toString(),
|
|
81
113
|
parentId: parentId ? parentId.toString() : undefined,
|
|
@@ -175,6 +175,7 @@
|
|
|
175
175
|
|
|
176
176
|
const folderType = '0';
|
|
177
177
|
const fileType = '1';
|
|
178
|
+
const branchType = '2';
|
|
178
179
|
|
|
179
180
|
let project = {};
|
|
180
181
|
let crowdinData = [];
|
|
@@ -409,10 +410,14 @@
|
|
|
409
410
|
{{/if}}
|
|
410
411
|
});
|
|
411
412
|
}
|
|
413
|
+
{{else}}
|
|
414
|
+
const settingsModal = undefined;
|
|
412
415
|
{{/if}}
|
|
413
416
|
|
|
414
417
|
{{#if infoModal}}
|
|
415
418
|
const infoModal = document.getElementById('info-modal');
|
|
419
|
+
{{else}}
|
|
420
|
+
const infoModal = undefined;
|
|
416
421
|
{{/if}}
|
|
417
422
|
|
|
418
423
|
document.addEventListener('keydown', (event) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crowdin/app-project-module",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"test": "jest --config jestconfig.json"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@crowdin/crowdin-apps-functions": "
|
|
16
|
+
"@crowdin/crowdin-apps-functions": "0.3.0",
|
|
17
17
|
"@types/pg": "^8.6.5",
|
|
18
18
|
"crypto-js": "^4.0.0",
|
|
19
19
|
"express": "4.17.1",
|