@crowdin/app-project-module 0.44.0 → 0.45.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/out/index.d.ts +3 -3
- package/out/index.js +52 -59
- package/out/middlewares/crowdin-client.d.ts +1 -1
- package/out/middlewares/crowdin-client.js +3 -2
- package/out/middlewares/integration-credentials.d.ts +2 -2
- package/out/middlewares/render-ui-module.d.ts +2 -2
- package/out/middlewares/ui-module.d.ts +2 -2
- package/out/middlewares/ui-module.js +3 -3
- package/out/{util → modules}/api/api.d.ts +2 -1
- package/out/{util → modules}/api/api.js +22 -22
- package/out/modules/api/index.d.ts +6 -0
- package/out/modules/api/index.js +14 -0
- package/out/modules/api/types.d.ts +20 -0
- package/out/modules/api/types.js +11 -0
- package/out/modules/context-menu/index.d.ts +1 -1
- package/out/modules/context-menu/index.js +2 -2
- package/out/modules/context-menu/types.d.ts +27 -0
- package/out/modules/context-menu/types.js +18 -0
- package/out/modules/custom-mt/handlers/translate.d.ts +1 -1
- package/out/modules/custom-mt/index.d.ts +1 -1
- package/out/modules/custom-mt/types.d.ts +1 -1
- package/out/modules/custom-spell-check/handlers/get-languages-list.d.ts +1 -1
- package/out/modules/custom-spell-check/handlers/spell-check.d.ts +1 -1
- package/out/modules/custom-spell-check/index.d.ts +1 -1
- package/out/modules/custom-spell-check/index.js +2 -2
- package/out/modules/custom-spell-check/types.d.ts +1 -1
- package/out/modules/editor-right-panel/index.d.ts +1 -1
- package/out/modules/editor-right-panel/index.js +2 -2
- package/out/modules/editor-right-panel/types.d.ts +1 -1
- package/out/modules/editor-themes/index.d.ts +1 -1
- package/out/modules/editor-themes/types.d.ts +17 -0
- package/out/modules/editor-themes/types.js +2 -0
- package/out/modules/file-processing/handlers/custom-file-format.d.ts +1 -1
- package/out/modules/file-processing/handlers/custom-file-format.js +1 -1
- package/out/modules/file-processing/handlers/file-download.d.ts +2 -2
- package/out/modules/file-processing/handlers/pre-post-process.d.ts +1 -1
- package/out/modules/file-processing/handlers/pre-post-process.js +1 -1
- package/out/modules/file-processing/index.d.ts +1 -1
- package/out/modules/file-processing/index.js +1 -1
- package/out/modules/file-processing/types.d.ts +1 -1
- package/out/modules/file-processing/util/defaults.d.ts +3 -0
- package/out/modules/file-processing/util/defaults.js +30 -0
- package/out/modules/file-processing/util/files.d.ts +6 -0
- package/out/modules/file-processing/util/files.js +47 -0
- package/out/modules/form-data-display.d.ts +1 -1
- package/out/modules/form-data-save.d.ts +1 -1
- package/out/modules/install.d.ts +2 -2
- package/out/modules/install.js +3 -3
- package/out/modules/integration/handlers/crowdin-file-progress.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-files.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-files.js +1 -1
- package/out/modules/integration/handlers/crowdin-project.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-update.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-update.js +7 -7
- package/out/modules/integration/handlers/crowdin-webhook.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-webhook.js +16 -5
- package/out/modules/integration/handlers/integration-data.d.ts +1 -1
- package/out/modules/integration/handlers/integration-data.js +2 -2
- package/out/modules/integration/handlers/integration-login.d.ts +1 -1
- package/out/modules/integration/handlers/integration-logout.d.ts +2 -2
- package/out/modules/integration/handlers/integration-logout.js +11 -4
- package/out/modules/integration/handlers/integration-update.d.ts +2 -2
- package/out/modules/integration/handlers/integration-update.js +7 -6
- package/out/modules/integration/handlers/integration-webhook.d.ts +2 -2
- package/out/modules/integration/handlers/integration-webhook.js +7 -2
- package/out/modules/integration/handlers/job-cancel.d.ts +1 -1
- package/out/modules/integration/handlers/job-cancel.js +2 -2
- package/out/modules/integration/handlers/job-info.d.ts +1 -1
- package/out/modules/integration/handlers/job-info.js +2 -2
- package/out/modules/integration/handlers/main.d.ts +2 -2
- package/out/modules/integration/handlers/main.js +3 -3
- package/out/modules/integration/handlers/oauth-login.d.ts +2 -2
- package/out/modules/integration/handlers/oauth-login.js +1 -1
- package/out/modules/integration/handlers/oauth-url.d.ts +1 -1
- package/out/modules/integration/handlers/oauth-url.js +1 -1
- package/out/modules/integration/handlers/settings-save.d.ts +2 -2
- package/out/modules/integration/handlers/settings-save.js +25 -8
- package/out/modules/integration/handlers/settings.d.ts +1 -1
- package/out/modules/integration/handlers/subscription-info.d.ts +1 -1
- package/out/modules/integration/handlers/subscription-info.js +2 -2
- package/out/modules/integration/handlers/sync-settings-save.d.ts +2 -2
- package/out/modules/integration/handlers/sync-settings-save.js +15 -7
- package/out/modules/integration/handlers/sync-settings.d.ts +1 -1
- package/out/modules/integration/handlers/user-errors.d.ts +1 -1
- package/out/modules/integration/index.d.ts +1 -1
- package/out/modules/integration/index.js +15 -10
- package/out/modules/integration/types.d.ts +2 -13
- package/out/modules/integration/util/cron.d.ts +27 -0
- package/out/{util → modules/integration/util}/cron.js +92 -23
- package/out/{util → modules/integration/util}/defaults.d.ts +2 -6
- package/out/{util → modules/integration/util}/defaults.js +1 -46
- package/out/modules/integration/util/files.d.ts +5 -0
- package/out/{util → modules/integration/util}/files.js +9 -40
- package/out/{util → modules/integration/util}/job.d.ts +1 -1
- package/out/{util → modules/integration/util}/job.js +11 -11
- package/out/{util/file-snapshot.d.ts → modules/integration/util/snapshot.d.ts} +2 -4
- package/out/{util/file-snapshot.js → modules/integration/util/snapshot.js} +4 -63
- package/out/{models/job.d.ts → modules/integration/util/types.d.ts} +14 -0
- package/out/modules/integration/util/webhooks.d.ts +48 -0
- package/out/{util → modules/integration/util}/webhooks.js +92 -46
- package/out/modules/manifest.d.ts +1 -1
- package/out/modules/manifest.js +6 -6
- package/out/modules/modal/index.d.ts +1 -1
- package/out/modules/modal/index.js +2 -2
- package/out/modules/organization-menu/index.d.ts +1 -1
- package/out/modules/organization-menu/index.js +1 -2
- package/out/modules/profile-resources-menu/index.d.ts +1 -1
- package/out/modules/profile-resources-menu/index.js +1 -2
- package/out/modules/project-menu/index.d.ts +1 -1
- package/out/modules/project-menu/index.js +2 -2
- package/out/modules/project-menu-crowdsource/index.d.ts +1 -1
- package/out/modules/project-menu-crowdsource/index.js +2 -2
- package/out/modules/project-reports/index.d.ts +1 -1
- package/out/modules/project-reports/index.js +1 -2
- package/out/modules/project-tools/index.d.ts +1 -1
- package/out/modules/project-tools/index.js +1 -2
- package/out/modules/subscription-paid.d.ts +1 -1
- package/out/modules/subscription-paid.js +2 -2
- package/out/modules/uninstall.d.ts +2 -2
- package/out/modules/uninstall.js +6 -2
- package/out/storage/index.d.ts +3 -2
- package/out/storage/mysql.d.ts +3 -2
- package/out/storage/mysql.js +3 -3
- package/out/storage/postgre.d.ts +3 -2
- package/out/storage/postgre.js +3 -3
- package/out/storage/sqlite.d.ts +3 -2
- package/out/storage/sqlite.js +3 -3
- package/out/storage/types.d.ts +9 -0
- package/out/storage/types.js +2 -0
- package/out/{models/index.d.ts → types.d.ts} +15 -83
- package/out/{models/index.js → types.js} +1 -24
- package/out/util/connection.d.ts +1 -9
- package/out/util/connection.js +54 -150
- package/out/util/handlebars.d.ts +1 -0
- package/out/util/handlebars.js +34 -0
- package/out/util/index.d.ts +2 -3
- package/out/util/index.js +6 -6
- package/out/util/logger.d.ts +1 -1
- package/out/util/subscription.d.ts +9 -0
- package/out/util/subscription.js +111 -0
- package/package.json +1 -1
- package/out/util/cron.d.ts +0 -8
- package/out/util/files.d.ts +0 -10
- package/out/util/webhooks.d.ts +0 -29
- /package/out/{util → modules}/api/base.d.ts +0 -0
- /package/out/{util → modules}/api/base.js +0 -0
- /package/out/{util → modules}/api/components.d.ts +0 -0
- /package/out/{util → modules}/api/components.js +0 -0
- /package/out/{models/job.js → modules/integration/util/types.js} +0 -0
package/out/storage/postgre.js
CHANGED
|
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.PostgreStorage = void 0;
|
|
14
14
|
const pg_1 = require("pg");
|
|
15
15
|
const uuid_1 = require("uuid");
|
|
16
|
-
const
|
|
16
|
+
const types_1 = require("../modules/integration/util/types");
|
|
17
17
|
const util_1 = require("../util");
|
|
18
18
|
class PostgreStorage {
|
|
19
19
|
constructor(config) {
|
|
@@ -169,7 +169,7 @@ class PostgreStorage {
|
|
|
169
169
|
type varchar not null,
|
|
170
170
|
title varchar null,
|
|
171
171
|
progress int default 0,
|
|
172
|
-
status varchar default '${
|
|
172
|
+
status varchar default '${types_1.JobStatus.CREATED}',
|
|
173
173
|
payload varchar null,
|
|
174
174
|
info varchar null,
|
|
175
175
|
data varchar null,
|
|
@@ -534,7 +534,7 @@ class PostgreStorage {
|
|
|
534
534
|
if (status) {
|
|
535
535
|
updateFields.push('status = $' + updateParams.length.toString());
|
|
536
536
|
updateParams.push(status);
|
|
537
|
-
if ((!progress || progress <= 100) && [
|
|
537
|
+
if ((!progress || progress <= 100) && [types_1.JobStatus.FAILED, types_1.JobStatus.CANCELED].includes(status)) {
|
|
538
538
|
updateFields.push('finished_at = $' + updateParams.length.toString());
|
|
539
539
|
updateParams.push(Date.now().toString());
|
|
540
540
|
}
|
package/out/storage/sqlite.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Storage } from '.';
|
|
2
|
-
import { CrowdinCredentials
|
|
3
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
2
|
+
import { CrowdinCredentials } from '../types';
|
|
4
3
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
4
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
|
|
5
|
+
import { UserErrors } from './types';
|
|
5
6
|
export interface SQLiteStorageConfig {
|
|
6
7
|
dbFolder: string;
|
|
7
8
|
}
|
package/out/storage/sqlite.js
CHANGED
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.SQLiteStorage = void 0;
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
19
|
-
const
|
|
19
|
+
const types_1 = require("../modules/integration/util/types");
|
|
20
20
|
class SQLiteStorage {
|
|
21
21
|
constructor(config) {
|
|
22
22
|
this.dbPromise = new Promise((res, rej) => {
|
|
@@ -247,7 +247,7 @@ class SQLiteStorage {
|
|
|
247
247
|
type varchar not null,
|
|
248
248
|
title varchar null,
|
|
249
249
|
progress integer DEFAULT 0,
|
|
250
|
-
status varchar DEFAULT '${
|
|
250
|
+
status varchar DEFAULT '${types_1.JobStatus.CREATED}',
|
|
251
251
|
payload varchar null,
|
|
252
252
|
info varchar null,
|
|
253
253
|
data varchar null,
|
|
@@ -524,7 +524,7 @@ class SQLiteStorage {
|
|
|
524
524
|
if (status) {
|
|
525
525
|
updateFields.push('status = ?');
|
|
526
526
|
updateParams.push(status);
|
|
527
|
-
if (!updateFields.includes('finished_at = ?') && [
|
|
527
|
+
if (!updateFields.includes('finished_at = ?') && [types_1.JobStatus.FAILED, types_1.JobStatus.CANCELED].includes(status)) {
|
|
528
528
|
updateFields.push('finished_at = ?');
|
|
529
529
|
updateParams.push(Date.now().toString());
|
|
530
530
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
2
2
|
import { JwtPayload, VerifyOptions } from '@crowdin/crowdin-apps-functions';
|
|
3
3
|
import { Request } from 'express';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
4
|
+
import { ContextModule } from './modules/context-menu/types';
|
|
5
|
+
import { CustomMTLogic } from './modules/custom-mt/types';
|
|
6
|
+
import { CustomSpellcheckerModule } from './modules/custom-spell-check/types';
|
|
7
|
+
import { EditorPanels } from './modules/editor-right-panel/types';
|
|
8
|
+
import { EditorThemes } from './modules/editor-themes/types';
|
|
9
|
+
import { CustomFileFormatLogic, FilePostExportLogic, FilePostImportLogic, FilePreExportLogic, FilePreImportLogic } from './modules/file-processing/types';
|
|
10
|
+
import { IntegrationLogic } from './modules/integration/types';
|
|
11
|
+
import { MySQLStorageConfig } from './storage/mysql';
|
|
12
|
+
import { PostgreStorageConfig } from './storage/postgre';
|
|
13
|
+
import { ApiModule } from './modules/api/types';
|
|
14
|
+
import { LogErrorFunction, LogFunction } from './util/logger';
|
|
12
15
|
export interface ClientConfig extends ImagePath {
|
|
13
16
|
/**
|
|
14
17
|
* Authentication Crowdin App type: "authorization_code", "crowdin_app". Default: "crowdin_app"
|
|
@@ -254,22 +257,6 @@ export interface SubscriptionInfo {
|
|
|
254
257
|
daysLeft?: number;
|
|
255
258
|
type?: SubscriptionInfoType;
|
|
256
259
|
}
|
|
257
|
-
export interface EditorThemes {
|
|
258
|
-
/**
|
|
259
|
-
* Module name
|
|
260
|
-
*/
|
|
261
|
-
name?: string;
|
|
262
|
-
/**
|
|
263
|
-
* Defines a set of CSS custom variables for theming purposes
|
|
264
|
-
*/
|
|
265
|
-
styles: {
|
|
266
|
-
[key: string]: string;
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* The Editor's mode list where the module will be available.
|
|
270
|
-
*/
|
|
271
|
-
modes: EditorMode[];
|
|
272
|
-
}
|
|
273
260
|
export declare enum EditorMode {
|
|
274
261
|
ASSETS = "assets",
|
|
275
262
|
REVIEW = "review",
|
|
@@ -282,36 +269,6 @@ interface ModuleContent {
|
|
|
282
269
|
*/
|
|
283
270
|
url?: string;
|
|
284
271
|
}
|
|
285
|
-
export interface ContextModule {
|
|
286
|
-
location: ContextOptionsLocations;
|
|
287
|
-
type: ContextOptionsTypes;
|
|
288
|
-
module: string;
|
|
289
|
-
/**
|
|
290
|
-
* Context menu name
|
|
291
|
-
*/
|
|
292
|
-
name?: string;
|
|
293
|
-
/**
|
|
294
|
-
* Support fileName pattern only. Contains fileName field regular expressions used to detect the file type. If the file name matches any of the regular expressions, the context menu will be displayed.
|
|
295
|
-
*/
|
|
296
|
-
signaturePatterns?: SignaturePatterns;
|
|
297
|
-
}
|
|
298
|
-
export interface SignaturePatterns {
|
|
299
|
-
fileName?: string;
|
|
300
|
-
fileContent?: string;
|
|
301
|
-
}
|
|
302
|
-
export declare enum ContextOptionsLocations {
|
|
303
|
-
TM = "tm",
|
|
304
|
-
GLOSSARY = "glossary",
|
|
305
|
-
LANGUAGE = "language",
|
|
306
|
-
SCREENSHOT = "screenshot",
|
|
307
|
-
SOURCE_FILE = "source_file",
|
|
308
|
-
TRANSLATED_FILE = "translated_file"
|
|
309
|
-
}
|
|
310
|
-
export declare enum ContextOptionsTypes {
|
|
311
|
-
MODAL = "modal",
|
|
312
|
-
NEW_TAB = "new_tab",
|
|
313
|
-
REDIRECT = "redirect"
|
|
314
|
-
}
|
|
315
272
|
export interface CrowdinAppUtilities extends CrowdinMetadataStore {
|
|
316
273
|
establishCrowdinConnection: (authRequest: string | CrowdinClientRequest) => Promise<{
|
|
317
274
|
context: CrowdinContextInfo;
|
|
@@ -368,41 +325,12 @@ export interface UiModule {
|
|
|
368
325
|
*/
|
|
369
326
|
name?: string;
|
|
370
327
|
}
|
|
371
|
-
export interface UserErrors {
|
|
372
|
-
id: number;
|
|
373
|
-
action: string;
|
|
374
|
-
message: string;
|
|
375
|
-
data: any;
|
|
376
|
-
createdAt: string;
|
|
377
|
-
crowdinId: string;
|
|
378
|
-
integrationId?: string;
|
|
379
|
-
}
|
|
380
328
|
export interface ImagePath {
|
|
381
329
|
/**
|
|
382
330
|
* path to app logo (e.g. {@example join(__dirname, 'logo.png')})
|
|
383
331
|
*/
|
|
384
332
|
imagePath?: string;
|
|
385
333
|
}
|
|
386
|
-
export declare enum RequestMethods {
|
|
387
|
-
GET = "GET",
|
|
388
|
-
POST = "POST",
|
|
389
|
-
PUT = "PUT",
|
|
390
|
-
PATCH = "PATCH",
|
|
391
|
-
DELETE = "DELETE"
|
|
392
|
-
}
|
|
393
|
-
export interface ApiEndpoints {
|
|
394
|
-
key: string;
|
|
395
|
-
name: string;
|
|
396
|
-
url: string;
|
|
397
|
-
method: RequestMethods;
|
|
398
|
-
description?: string;
|
|
399
|
-
documentationUrl?: string;
|
|
400
|
-
}
|
|
401
|
-
export interface ApiModule {
|
|
402
|
-
default?: boolean;
|
|
403
|
-
endpoints?: ApiEndpoints[];
|
|
404
|
-
docFile?: string;
|
|
405
|
-
}
|
|
406
334
|
export interface Logger {
|
|
407
335
|
enabled: boolean;
|
|
408
336
|
log?: (message: string, context?: CrowdinContextInfo) => void;
|
|
@@ -439,4 +367,8 @@ export interface AWSConfig {
|
|
|
439
367
|
*/
|
|
440
368
|
region?: string;
|
|
441
369
|
}
|
|
370
|
+
export interface SignaturePatterns {
|
|
371
|
+
fileName?: string;
|
|
372
|
+
fileContent?: string;
|
|
373
|
+
}
|
|
442
374
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectPermissions = exports.UserPermissions = exports.
|
|
3
|
+
exports.ProjectPermissions = exports.UserPermissions = exports.EditorMode = exports.SubscriptionInfoType = exports.AccountType = exports.Scope = exports.AuthenticationType = void 0;
|
|
4
4
|
var AuthenticationType;
|
|
5
5
|
(function (AuthenticationType) {
|
|
6
6
|
AuthenticationType["CODE"] = "authorization_code";
|
|
@@ -45,29 +45,6 @@ var EditorMode;
|
|
|
45
45
|
EditorMode["TRANSLATE"] = "TRANSLATE";
|
|
46
46
|
EditorMode["PROOFREAD"] = "proofread";
|
|
47
47
|
})(EditorMode = exports.EditorMode || (exports.EditorMode = {}));
|
|
48
|
-
var ContextOptionsLocations;
|
|
49
|
-
(function (ContextOptionsLocations) {
|
|
50
|
-
ContextOptionsLocations["TM"] = "tm";
|
|
51
|
-
ContextOptionsLocations["GLOSSARY"] = "glossary";
|
|
52
|
-
ContextOptionsLocations["LANGUAGE"] = "language";
|
|
53
|
-
ContextOptionsLocations["SCREENSHOT"] = "screenshot";
|
|
54
|
-
ContextOptionsLocations["SOURCE_FILE"] = "source_file";
|
|
55
|
-
ContextOptionsLocations["TRANSLATED_FILE"] = "translated_file";
|
|
56
|
-
})(ContextOptionsLocations = exports.ContextOptionsLocations || (exports.ContextOptionsLocations = {}));
|
|
57
|
-
var ContextOptionsTypes;
|
|
58
|
-
(function (ContextOptionsTypes) {
|
|
59
|
-
ContextOptionsTypes["MODAL"] = "modal";
|
|
60
|
-
ContextOptionsTypes["NEW_TAB"] = "new_tab";
|
|
61
|
-
ContextOptionsTypes["REDIRECT"] = "redirect";
|
|
62
|
-
})(ContextOptionsTypes = exports.ContextOptionsTypes || (exports.ContextOptionsTypes = {}));
|
|
63
|
-
var RequestMethods;
|
|
64
|
-
(function (RequestMethods) {
|
|
65
|
-
RequestMethods["GET"] = "GET";
|
|
66
|
-
RequestMethods["POST"] = "POST";
|
|
67
|
-
RequestMethods["PUT"] = "PUT";
|
|
68
|
-
RequestMethods["PATCH"] = "PATCH";
|
|
69
|
-
RequestMethods["DELETE"] = "DELETE";
|
|
70
|
-
})(RequestMethods = exports.RequestMethods || (exports.RequestMethods = {}));
|
|
71
48
|
var UserPermissions;
|
|
72
49
|
(function (UserPermissions) {
|
|
73
50
|
UserPermissions["OWNER"] = "owner";
|
package/out/util/connection.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
2
|
-
import { AccountType, Config, CrowdinContextInfo, CrowdinCredentials, SubscriptionInfo, UnauthorizedConfig } from '../models';
|
|
3
2
|
import { IntegrationCredentials, IntegrationLogic } from '../modules/integration/types';
|
|
3
|
+
import { Config, CrowdinContextInfo, CrowdinCredentials } from '../types';
|
|
4
4
|
export declare function prepareCrowdinClient({ config, credentials, autoRenew, context, }: {
|
|
5
5
|
config: Config;
|
|
6
6
|
credentials: CrowdinCredentials;
|
|
@@ -11,11 +11,3 @@ export declare function prepareCrowdinClient({ config, credentials, autoRenew, c
|
|
|
11
11
|
token: string;
|
|
12
12
|
}>;
|
|
13
13
|
export declare function prepareIntegrationCredentials(config: Config, integration: IntegrationLogic, integrationCredentials: IntegrationCredentials): Promise<any>;
|
|
14
|
-
export declare function clearCache(organization: string): void;
|
|
15
|
-
export declare function isAppFree(config: Config | UnauthorizedConfig): boolean;
|
|
16
|
-
export declare function checkSubscription({ config, token, organization, accountType, }: {
|
|
17
|
-
config: Config;
|
|
18
|
-
token: string;
|
|
19
|
-
organization: string;
|
|
20
|
-
accountType: AccountType;
|
|
21
|
-
}): Promise<SubscriptionInfo>;
|
package/out/util/connection.js
CHANGED
|
@@ -12,54 +12,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = void 0;
|
|
16
16
|
const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
|
|
17
17
|
const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const _1 = require(".");
|
|
20
|
-
const models_1 = require("../models");
|
|
21
20
|
const storage_1 = require("../storage");
|
|
21
|
+
const types_1 = require("../types");
|
|
22
22
|
const axios_2 = require("./axios");
|
|
23
23
|
const logger_1 = require("./logger");
|
|
24
24
|
const axiosCustom = new axios_2.AxiosProvider().axios;
|
|
25
|
-
function refreshToken(config, credentials) {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
if (config.authenticationType === models_1.AuthenticationType.CODE) {
|
|
29
|
-
const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)({
|
|
30
|
-
clientId: config.clientId,
|
|
31
|
-
clientSecret: config.clientSecret,
|
|
32
|
-
refreshToken: (0, _1.decryptData)(config, credentials.refreshToken),
|
|
33
|
-
url: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl,
|
|
34
|
-
});
|
|
35
|
-
return {
|
|
36
|
-
accessToken: (0, _1.encryptData)(config, token.accessToken),
|
|
37
|
-
refreshToken: (0, _1.encryptData)(config, token.refreshToken),
|
|
38
|
-
expiresIn: token.expiresIn,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
|
|
42
|
-
appId: config.identifier,
|
|
43
|
-
appSecret: credentials.appSecret,
|
|
44
|
-
clientId: config.clientId,
|
|
45
|
-
clientSecret: config.clientSecret,
|
|
46
|
-
domain: credentials.domain || '',
|
|
47
|
-
userId: credentials.userId,
|
|
48
|
-
url: (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl,
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
accessToken: (0, _1.encryptData)(config, token.accessToken),
|
|
52
|
-
expiresIn: token.expiresIn,
|
|
53
|
-
refreshToken: '',
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
25
|
function prepareCrowdinClient({ config, credentials, autoRenew = false, context, }) {
|
|
58
26
|
var _a, _b;
|
|
59
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
28
|
//2 min as an extra buffer
|
|
61
29
|
const isExpired = +credentials.expire - 120 < Date.now() / 1000;
|
|
62
|
-
const organization = credentials.type ===
|
|
30
|
+
const organization = credentials.type === types_1.AccountType.ENTERPRISE ? credentials.id : undefined;
|
|
63
31
|
let token;
|
|
64
32
|
let crowdinCreds;
|
|
65
33
|
if (!isExpired) {
|
|
@@ -211,31 +179,6 @@ function prepareCrowdinClient({ config, credentials, autoRenew = false, context,
|
|
|
211
179
|
});
|
|
212
180
|
}
|
|
213
181
|
exports.prepareCrowdinClient = prepareCrowdinClient;
|
|
214
|
-
function refreshCrowdinCreds({ config, credentials }) {
|
|
215
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
(0, logger_1.log)('Crowdin credentials have expired. Requesting a new credentials');
|
|
217
|
-
const newCredentials = yield refreshToken(config, credentials);
|
|
218
|
-
(0, logger_1.log)('Saving updated crowdin credentials in the database');
|
|
219
|
-
const newCrowdinCredentials = {
|
|
220
|
-
id: credentials.id,
|
|
221
|
-
appSecret: credentials.appSecret,
|
|
222
|
-
domain: credentials.domain,
|
|
223
|
-
userId: credentials.userId,
|
|
224
|
-
organizationId: credentials.organizationId,
|
|
225
|
-
baseUrl: credentials.baseUrl,
|
|
226
|
-
refreshToken: newCredentials.refreshToken,
|
|
227
|
-
accessToken: newCredentials.accessToken,
|
|
228
|
-
expire: (new Date().getTime() / 1000 + newCredentials.expiresIn).toString(),
|
|
229
|
-
type: credentials.type,
|
|
230
|
-
};
|
|
231
|
-
yield (0, storage_1.getStorage)().updateCrowdinCredentials(newCrowdinCredentials);
|
|
232
|
-
const token = (0, _1.decryptData)(config, newCredentials.accessToken);
|
|
233
|
-
return {
|
|
234
|
-
credentials: newCrowdinCredentials,
|
|
235
|
-
token,
|
|
236
|
-
};
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
182
|
function prepareIntegrationCredentials(config, integration, integrationCredentials) {
|
|
240
183
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
241
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -279,99 +222,60 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
|
|
|
279
222
|
});
|
|
280
223
|
}
|
|
281
224
|
exports.prepareIntegrationCredentials = prepareIntegrationCredentials;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return !config.pricing || config.pricing.planType === 'free';
|
|
307
|
-
}
|
|
308
|
-
exports.isAppFree = isAppFree;
|
|
309
|
-
function validateSubscription(date) {
|
|
310
|
-
const expired = date.getTime() < Date.now();
|
|
311
|
-
const daysLeft = Math.round((date.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
|
|
312
|
-
return { expired, daysLeft };
|
|
225
|
+
function refreshCrowdinCreds({ config, credentials }) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
(0, logger_1.log)('Crowdin credentials have expired. Requesting a new credentials');
|
|
228
|
+
const newCredentials = yield refreshToken(config, credentials);
|
|
229
|
+
(0, logger_1.log)('Saving updated crowdin credentials in the database');
|
|
230
|
+
const newCrowdinCredentials = {
|
|
231
|
+
id: credentials.id,
|
|
232
|
+
appSecret: credentials.appSecret,
|
|
233
|
+
domain: credentials.domain,
|
|
234
|
+
userId: credentials.userId,
|
|
235
|
+
organizationId: credentials.organizationId,
|
|
236
|
+
baseUrl: credentials.baseUrl,
|
|
237
|
+
refreshToken: newCredentials.refreshToken,
|
|
238
|
+
accessToken: newCredentials.accessToken,
|
|
239
|
+
expire: (new Date().getTime() / 1000 + newCredentials.expiresIn).toString(),
|
|
240
|
+
type: credentials.type,
|
|
241
|
+
};
|
|
242
|
+
yield (0, storage_1.getStorage)().updateCrowdinCredentials(newCrowdinCredentials);
|
|
243
|
+
const token = (0, _1.decryptData)(config, newCredentials.accessToken);
|
|
244
|
+
return {
|
|
245
|
+
credentials: newCrowdinCredentials,
|
|
246
|
+
token,
|
|
247
|
+
};
|
|
248
|
+
});
|
|
313
249
|
}
|
|
314
|
-
function
|
|
315
|
-
var _a, _b
|
|
250
|
+
function refreshToken(config, credentials) {
|
|
251
|
+
var _a, _b;
|
|
316
252
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (cacheEntry) {
|
|
324
|
-
const { cacheValidUntil, validUntil, subscribeLink, type } = cacheEntry;
|
|
325
|
-
if (cacheValidUntil.getTime() > Date.now()) {
|
|
326
|
-
(0, logger_1.log)(`Loaded data from cache. Subscription is valid until ${validUntil.toISOString()}`);
|
|
327
|
-
const { expired, daysLeft } = validateSubscription(new Date(validUntil));
|
|
328
|
-
(0, logger_1.log)(`expired ${expired}`);
|
|
329
|
-
return { expired, subscribeLink, daysLeft, type };
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
try {
|
|
333
|
-
const subscription = yield (0, crowdin_apps_functions_1.getSubscription)({
|
|
334
|
-
appIdentifier,
|
|
335
|
-
organization: accountType === models_1.AccountType.ENTERPRISE ? organization : undefined,
|
|
336
|
-
token,
|
|
337
|
-
baseUrl: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.subscriptionUrl,
|
|
253
|
+
if (config.authenticationType === types_1.AuthenticationType.CODE) {
|
|
254
|
+
const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)({
|
|
255
|
+
clientId: config.clientId,
|
|
256
|
+
clientSecret: config.clientSecret,
|
|
257
|
+
refreshToken: (0, _1.decryptData)(config, credentials.refreshToken),
|
|
258
|
+
url: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl,
|
|
338
259
|
});
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
catch (e) {
|
|
346
|
-
if (e instanceof crowdin_apps_functions_1.PaymentRequiredError) {
|
|
347
|
-
const { initializedAt, subscribeLink } = e;
|
|
348
|
-
(0, logger_1.log)(`Recieved 402 payment error. initializedAt ${initializedAt}`);
|
|
349
|
-
//default 2 weeks
|
|
350
|
-
const defaultSubscriptionPlan = 14;
|
|
351
|
-
let days;
|
|
352
|
-
if (accountType === models_1.AccountType.ENTERPRISE) {
|
|
353
|
-
days = ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trialEnterprise) || ((_d = config.pricing) === null || _d === void 0 ? void 0 : _d.trial) || defaultSubscriptionPlan;
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
days = ((_e = config.pricing) === null || _e === void 0 ? void 0 : _e.trialCrowdin) || ((_f = config.pricing) === null || _f === void 0 ? void 0 : _f.trial) || defaultSubscriptionPlan;
|
|
357
|
-
}
|
|
358
|
-
(0, logger_1.log)(`Subscriptino trial plan ${days} days`);
|
|
359
|
-
const date = new Date(initializedAt);
|
|
360
|
-
date.setDate(date.getDate() + days);
|
|
361
|
-
const { expired, daysLeft } = validateSubscription(date);
|
|
362
|
-
(0, logger_1.log)(`expired ${expired}`);
|
|
363
|
-
addToCache(organization, appIdentifier, new Date(date), models_1.SubscriptionInfoType.TRIAL, (_g = config.pricing) === null || _g === void 0 ? void 0 : _g.cachingSeconds, subscribeLink);
|
|
364
|
-
return { expired, subscribeLink, daysLeft, type: models_1.SubscriptionInfoType.TRIAL };
|
|
365
|
-
}
|
|
366
|
-
if (config.onError) {
|
|
367
|
-
config.onError(e);
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
console.error(e);
|
|
371
|
-
}
|
|
372
|
-
(0, logger_1.log)('Recieved http error from subscription request. Returning expired=false');
|
|
373
|
-
return { expired: false };
|
|
260
|
+
return {
|
|
261
|
+
accessToken: (0, _1.encryptData)(config, token.accessToken),
|
|
262
|
+
refreshToken: (0, _1.encryptData)(config, token.refreshToken),
|
|
263
|
+
expiresIn: token.expiresIn,
|
|
264
|
+
};
|
|
374
265
|
}
|
|
266
|
+
const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
|
|
267
|
+
appId: config.identifier,
|
|
268
|
+
appSecret: credentials.appSecret,
|
|
269
|
+
clientId: config.clientId,
|
|
270
|
+
clientSecret: config.clientSecret,
|
|
271
|
+
domain: credentials.domain || '',
|
|
272
|
+
userId: credentials.userId,
|
|
273
|
+
url: (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl,
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
accessToken: (0, _1.encryptData)(config, token.accessToken),
|
|
277
|
+
expiresIn: token.expiresIn,
|
|
278
|
+
refreshToken: '',
|
|
279
|
+
};
|
|
375
280
|
});
|
|
376
281
|
}
|
|
377
|
-
exports.checkSubscription = checkSubscription;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const engine: (path: string, options: object, callback: (e: any, rendered: string) => void) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
exports.engine = void 0;
|
|
7
|
+
const express_handlebars_1 = __importDefault(require("express-handlebars"));
|
|
8
|
+
exports.engine = (0, express_handlebars_1.default)({
|
|
9
|
+
layoutsDir: '',
|
|
10
|
+
defaultLayout: '',
|
|
11
|
+
helpers: {
|
|
12
|
+
ifeq: function (a, b, options) {
|
|
13
|
+
if (a === b) {
|
|
14
|
+
return options.fn(this);
|
|
15
|
+
}
|
|
16
|
+
return options.inverse(this);
|
|
17
|
+
},
|
|
18
|
+
checkLength: function (a, b, options) {
|
|
19
|
+
if (a.length > b) {
|
|
20
|
+
return options.fn(this);
|
|
21
|
+
}
|
|
22
|
+
return options.inverse(this);
|
|
23
|
+
},
|
|
24
|
+
in: function (a, b, options) {
|
|
25
|
+
if (a.toString().includes(b.toString())) {
|
|
26
|
+
return options.fn(this);
|
|
27
|
+
}
|
|
28
|
+
return options.inverse(this);
|
|
29
|
+
},
|
|
30
|
+
or: function (a, b, options) {
|
|
31
|
+
return a || b ? options.fn(this) : options.inverse(this);
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
package/out/util/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
|
-
import { Config, CrowdinClientRequest, ImagePath } from '../
|
|
3
|
-
import { ExtendedResult } from '../modules/integration/types';
|
|
2
|
+
import { Config, CrowdinClientRequest, ImagePath, UnauthorizedConfig } from '../types';
|
|
4
3
|
export declare class CodeError extends Error {
|
|
5
4
|
code: number | undefined;
|
|
6
5
|
constructor(message: string, code?: number);
|
|
@@ -9,5 +8,5 @@ export declare function runAsyncWrapper(callback: Function): (req: Request | Cro
|
|
|
9
8
|
export declare function encryptData(config: Config, data: string): string;
|
|
10
9
|
export declare function decryptData(config: Config, data: string): string;
|
|
11
10
|
export declare function executeWithRetry<T>(func: () => Promise<T>, numOfRetries?: number): Promise<T>;
|
|
12
|
-
export declare function isExtendedResultType<T>(data?: T | ExtendedResult<T>): data is ExtendedResult<T>;
|
|
13
11
|
export declare function getLogoUrl(moduleConfig?: ImagePath, modulePath?: string): string;
|
|
12
|
+
export declare function isAuthorizedConfig(config: Config | UnauthorizedConfig): config is Config;
|
package/out/util/index.js
CHANGED
|
@@ -32,9 +32,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
35
|
+
exports.isAuthorizedConfig = exports.getLogoUrl = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
|
|
36
36
|
const crypto = __importStar(require("crypto-js"));
|
|
37
37
|
const storage_1 = require("../storage");
|
|
38
|
+
const types_1 = require("../types");
|
|
38
39
|
const logger_1 = require("./logger");
|
|
39
40
|
class CodeError extends Error {
|
|
40
41
|
constructor(message, code) {
|
|
@@ -100,11 +101,6 @@ function executeWithRetry(func, numOfRetries = 2) {
|
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
exports.executeWithRetry = executeWithRetry;
|
|
103
|
-
function isExtendedResultType(data) {
|
|
104
|
-
const dataTyped = data;
|
|
105
|
-
return !!dataTyped && !Array.isArray(dataTyped);
|
|
106
|
-
}
|
|
107
|
-
exports.isExtendedResultType = isExtendedResultType;
|
|
108
104
|
function getLogoUrl(moduleConfig, modulePath) {
|
|
109
105
|
if (!moduleConfig && !modulePath) {
|
|
110
106
|
return '/logo.png';
|
|
@@ -112,3 +108,7 @@ function getLogoUrl(moduleConfig, modulePath) {
|
|
|
112
108
|
return `/logo${modulePath}/logo.png`;
|
|
113
109
|
}
|
|
114
110
|
exports.getLogoUrl = getLogoUrl;
|
|
111
|
+
function isAuthorizedConfig(config) {
|
|
112
|
+
return !!config.clientId && !!config.clientSecret && config.authenticationType !== types_1.AuthenticationType.NONE;
|
|
113
|
+
}
|
|
114
|
+
exports.isAuthorizedConfig = isAuthorizedConfig;
|
package/out/util/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosError } from 'axios';
|
|
2
|
-
import { Config, CrowdinContextInfo, UnauthorizedConfig } from '../
|
|
2
|
+
import { Config, CrowdinContextInfo, UnauthorizedConfig } from '../types';
|
|
3
3
|
export type LogFunction = (message: string) => void;
|
|
4
4
|
export type LogErrorFunction = (error: any) => void;
|
|
5
5
|
export type LogContext = {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccountType, Config, SubscriptionInfo, UnauthorizedConfig } from '../types';
|
|
2
|
+
export declare function isAppFree(config: Config | UnauthorizedConfig): boolean;
|
|
3
|
+
export declare function checkSubscription({ config, token, organization, accountType, }: {
|
|
4
|
+
config: Config;
|
|
5
|
+
token: string;
|
|
6
|
+
organization: string;
|
|
7
|
+
accountType: AccountType;
|
|
8
|
+
}): Promise<SubscriptionInfo>;
|
|
9
|
+
export declare function clearCache(organization: string): void;
|