@crowdin/app-project-module 0.26.5 → 0.27.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 CHANGED
@@ -129,6 +129,28 @@ const configuration = {
129
129
  stopPagination: true, //send if no next files page
130
130
  };
131
131
  },
132
+ getFileProgress: async (projectId, client, fileId) => { //Use this function if you require a customized translation progress.
133
+ return {
134
+ [fileId]: [
135
+ {
136
+ languageId: 'uk',
137
+ eTag: '49a76a1632973b00175dac942976f7c6',
138
+ words: {
139
+ total: 180,
140
+ translated: 0,
141
+ approved: 0
142
+ },
143
+ phrases: {
144
+ total: 6,
145
+ translated: 0,
146
+ approved: 0
147
+ },
148
+ translationProgress: 100,
149
+ approvalProgress: 0
150
+ }
151
+ ]
152
+ }
153
+ },
132
154
  updateCrowdin: async (projectId, client, credentials, request, rootFolder, appSettings) => {
133
155
  //here you need to get data from integration and upload it to Crowdin
134
156
  console.log(`Request for updating data in Crowdin ${JSON.stringify(request)}`);
@@ -230,6 +252,9 @@ configuration.projectIntegration.loginForm = {
230
252
  label: 'Password',
231
253
  type: 'password'
232
254
  },
255
+ {
256
+ label: 'Api creds',
257
+ },
233
258
  {
234
259
  helpText: 'Api Key for http requests',
235
260
  key: 'apiKey',
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- import { Config } from '../models';
4
- export default function handle(config: Config): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { Config, IntegrationLogic } from '../models';
4
+ export default function handle(config: Config, integration: IntegrationLogic): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -10,13 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const util_1 = require("../util");
13
- function handle(config) {
13
+ function handle(config, integration) {
14
14
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
15
15
  const fileId = Number(req.params.fileId);
16
16
  (0, util_1.log)(`Loading translation progress for file ${fileId}`, config.logger);
17
- const progress = yield req.crowdinApiClient.translationStatusApi.getFileProgress(req.crowdinContext.jwtPayload.context.project_id, fileId);
18
- (0, util_1.log)(`Translation progress for file ${fileId} ${JSON.stringify(progress.data, null, 2)}`, config.logger);
19
- res.send({ [fileId]: progress.data.map((e) => e.data) });
17
+ if (integration.getFileProgress) {
18
+ const progress = yield integration.getFileProgress(req.crowdinContext.jwtPayload.context.project_id, req.crowdinApiClient, fileId);
19
+ (0, util_1.log)(`Translation progress for file ${fileId} ${JSON.stringify(progress, null, 2)}`, config.logger);
20
+ res.send(progress);
21
+ }
22
+ else {
23
+ res.send({});
24
+ }
20
25
  }), config.onError);
21
26
  }
22
27
  exports.default = handle;
package/out/index.js CHANGED
@@ -115,7 +115,7 @@ function addCrowdinEndpoints(app, plainConfig) {
115
115
  app.post('/api/logout', (0, crowdin_client_1.default)(config, false, false), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_logout_1.default)(config, integrationLogic));
116
116
  app.get('/api/crowdin/files', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, crowdin_files_1.default)(config, integrationLogic));
117
117
  app.get('/api/crowdin/project', json_response_1.default, (0, crowdin_client_1.default)(config), (0, crowdin_project_1.default)(config));
118
- app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config));
118
+ app.get('/api/crowdin/file-progress/:fileId', (0, crowdin_client_1.default)(config), (0, crowdin_file_progress_1.default)(config, integrationLogic));
119
119
  app.get('/api/integration/data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_data_1.default)(config, integrationLogic));
120
120
  app.post('/api/crowdin/update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, crowdin_update_1.default)(config, integrationLogic));
121
121
  app.post('/api/integration/update', json_response_1.default, (0, crowdin_client_1.default)(config), (0, integration_credentials_1.default)(config, integrationLogic), (0, integration_update_1.default)(config, integrationLogic));
@@ -1,4 +1,4 @@
1
- import Crowdin, { LanguagesModel, SourceFilesModel, SourceStringsModel } from '@crowdin/crowdin-api-client';
1
+ import Crowdin, { LanguagesModel, SourceFilesModel, SourceStringsModel, TranslationStatusModel } from '@crowdin/crowdin-api-client';
2
2
  import { JwtPayload, VerifyOptions } from '@crowdin/crowdin-apps-functions';
3
3
  import { Request } from 'express';
4
4
  import { MySQLStorageConfig } from '../storage/mysql';
@@ -195,7 +195,7 @@ export interface IntegrationLogic {
195
195
  /**
196
196
  * function to define configuration(settings) modal for you app (by default app will not have any custom settings)
197
197
  */
198
- getConfiguration?: (projectId: number, client: Crowdin, apiCredentials: any) => Promise<ConfigurationModalEntity[]>;
198
+ getConfiguration?: (projectId: number, client: Crowdin, apiCredentials: any) => Promise<FormEntity[]>;
199
199
  /**
200
200
  * Logout hook for cleanup logic
201
201
  */
@@ -235,13 +235,19 @@ export interface IntegrationLogic {
235
235
  * Enable integration next page event
236
236
  */
237
237
  integrationPagination?: boolean;
238
+ /**
239
+ * function to get crowdin file translation progress
240
+ */
241
+ getFileProgress?: (projectId: number, client: Crowdin, fileId: number) => Promise<{
242
+ [key: number]: TranslationStatusModel.LanguageProgress[];
243
+ }>;
238
244
  }
239
- export declare type ConfigurationModalEntity = FormField | ConfigurationDelimeter;
240
- export interface ConfigurationDelimeter {
245
+ export declare type FormEntity = FormField | FormDelimeter;
246
+ export interface FormDelimeter {
241
247
  label: string;
242
248
  }
243
249
  export interface LoginForm {
244
- fields: FormField[];
250
+ fields: FormEntity[];
245
251
  }
246
252
  export interface OAuthLogin {
247
253
  /**
@@ -118,6 +118,12 @@ function applyDefaults(config, integration) {
118
118
  return res;
119
119
  });
120
120
  }
121
+ if (!integration.getFileProgress) {
122
+ integration.getFileProgress = (projectId, client, fileId) => __awaiter(this, void 0, void 0, function* () {
123
+ const progress = yield client.translationStatusApi.getFileProgress(projectId, fileId);
124
+ return { [fileId]: progress.data.map((e) => e.data) };
125
+ });
126
+ }
121
127
  if (!integration.loginForm) {
122
128
  integration.loginForm = {
123
129
  fields: [
@@ -10,64 +10,69 @@
10
10
  <crowdin-h4 id="integration-name">{{ name }}</crowdin-h4>
11
11
  <div class="inputs">
12
12
  {{#each loginFields}}
13
- {{#ifeq type "checkbox"}}
14
- <crowdin-checkbox
15
- id="{{key}}"
16
- label="{{label}}"
17
- value="false"
18
- use-switch
19
- {{#if helpText}}
20
- help-text="{{helpText}}"
21
- {{/if}}
22
- {{#if helpTextHtml}}
23
- help-text-html="{{helpTextHtml}}"
24
- {{/if}}
25
- {{#ifeq defaultValue true}}
26
- checked="{{defaultValue}}"
27
- {{/ifeq}}
28
- >
29
- </crowdin-checkbox>
30
- {{else}}
31
- {{#ifeq type "select"}}
32
- <crowdin-select
33
- {{#if isMulti}}
34
- is-multi
35
- close-on-select="false"
36
- {{/if}}
37
- {{#if isSearchable}}
38
- is-searchable
39
- {{/if}}
13
+ {{#if key}}
14
+ {{#ifeq type "checkbox"}}
15
+ <crowdin-checkbox
40
16
  id="{{key}}"
41
17
  label="{{label}}"
18
+ value="false"
19
+ use-switch
42
20
  {{#if helpText}}
43
21
  help-text="{{helpText}}"
44
22
  {{/if}}
45
23
  {{#if helpTextHtml}}
46
24
  help-text-html="{{helpTextHtml}}"
47
25
  {{/if}}
26
+ {{#ifeq defaultValue true}}
27
+ checked="{{defaultValue}}"
28
+ {{/ifeq}}
48
29
  >
49
- {{#each options}}
50
- <option {{#ifeq ../defaultValue value}} selected {{/ifeq}} value="{{value}}">{{label}}</option>
51
- {{/each}}
52
- </crowdin-select>
30
+ </crowdin-checkbox>
53
31
  {{else}}
54
- <crowdin-input
55
- id="{{key}}"
56
- label="{{label}}"
57
- {{#if helpText}}
58
- help-text="{{helpText}}"
59
- {{/if}}
60
- {{#if helpTextHtml}}
61
- help-text-html="{{helpTextHtml}}"
62
- {{/if}}
63
- {{#if type}}
64
- type="{{type}}"
65
- {{/if}}
66
- value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
67
- </crowdin-input>
32
+ {{#ifeq type "select"}}
33
+ <crowdin-select
34
+ {{#if isMulti}}
35
+ is-multi
36
+ close-on-select="false"
37
+ {{/if}}
38
+ {{#if isSearchable}}
39
+ is-searchable
40
+ {{/if}}
41
+ id="{{key}}"
42
+ label="{{label}}"
43
+ {{#if helpText}}
44
+ help-text="{{helpText}}"
45
+ {{/if}}
46
+ {{#if helpTextHtml}}
47
+ help-text-html="{{helpTextHtml}}"
48
+ {{/if}}
49
+ >
50
+ {{#each options}}
51
+ <option {{#ifeq ../defaultValue value}} selected {{/ifeq}} value="{{value}}">{{label}}</option>
52
+ {{/each}}
53
+ </crowdin-select>
54
+ {{else}}
55
+ <crowdin-input
56
+ id="{{key}}"
57
+ label="{{label}}"
58
+ {{#if helpText}}
59
+ help-text="{{helpText}}"
60
+ {{/if}}
61
+ {{#if helpTextHtml}}
62
+ help-text-html="{{helpTextHtml}}"
63
+ {{/if}}
64
+ {{#if type}}
65
+ type="{{type}}"
66
+ {{/if}}
67
+ value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
68
+ </crowdin-input>
68
69
  {{/ifeq}}
69
70
  {{/ifeq}}
70
- {{/each}}
71
+ {{else}}
72
+ <crowdin-p>{{label}}</crowdin-p>
73
+ {{/if}}
74
+ <div style="padding: 8px"></div>
75
+ {{/each}}
71
76
  </div>
72
77
  <crowdin-button
73
78
  outlined icon-after="arrow_forward"
@@ -153,11 +158,13 @@
153
158
  function getLoginForm() {
154
159
  return {
155
160
  {{#each loginFields}}
156
- {{#ifeq type "checkbox"}}
157
- '{{key}}': !!document.querySelector('#{{key}}').checked,
158
- {{else}}
159
- '{{key}}': document.querySelector('#{{key}}').getAttribute('value'),
160
- {{/ifeq}}
161
+ {{#if key}}
162
+ {{#ifeq type "checkbox"}}
163
+ '{{key}}': !!document.querySelector('#{{key}}').checked,
164
+ {{else}}
165
+ '{{key}}': document.querySelector('#{{key}}').getAttribute('value'),
166
+ {{/ifeq}}
167
+ {{/if}}
161
168
  {{/each}}
162
169
  };
163
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.26.5",
3
+ "version": "0.27.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",