@crowdin/app-project-module 0.28.7 → 0.28.9

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.
@@ -1,143 +1,94 @@
1
1
  if (!window.Promise) {
2
- window.Promise = Promise;
2
+ window.Promise = Promise;
3
3
  }
4
4
 
5
5
  const urlParams = new URLSearchParams(window.location.search);
6
6
  const origin = urlParams.get('origin');
7
7
  const clientId = urlParams.get('client_id');
8
- const tokenJwt = urlParams.get('tokenJwt');
9
8
  let restParams = window.location.search;
10
9
  const frameData = JSON.parse(window.name);
11
10
 
12
11
  const postPromises = {};
13
12
 
14
- function parentWindowPostMessage(data) {
15
- return new Promise((resolve, reject) => {
16
- window.parent.postMessage(JSON.stringify(data), origin);
17
- const timerId = setTimeout(() => {
18
- reject();
19
- }, 10000);
20
- postPromises[data.uid] = { resolve: resolve, timer: timerId };
21
- });
22
- }
23
-
24
13
  window.addEventListener('message', handleMessage);
25
14
 
26
15
  function isJson(string) {
27
- try {
28
- JSON.parse(string);
29
- } catch (e) {
30
- return false;
31
- }
16
+ try {
17
+ JSON.parse(string);
18
+ } catch (e) {
19
+ return false;
20
+ }
32
21
 
33
- return true;
22
+ return true;
34
23
  }
35
24
 
36
25
  function handleMessage(event) {
37
- const eventData =
38
- event.data && typeof event.data === 'string' && isJson(event.data) ? JSON.parse(event.data) : {};
39
- if (postPromises[eventData.uid]) {
40
- if (postPromises[eventData.uid].timer) {
41
- clearTimeout(postPromises[eventData.uid].timer);
26
+ const eventData = event.data && typeof event.data === 'string' && isJson(event.data) ? JSON.parse(event.data) : {};
27
+ if (postPromises[eventData.uid]) {
28
+ if (postPromises[eventData.uid].timer) {
29
+ clearTimeout(postPromises[eventData.uid].timer);
30
+ }
31
+ postPromises[eventData.uid].resolve(eventData.data);
42
32
  }
43
- postPromises[eventData.uid].resolve(eventData.data);
44
- }
45
33
  }
46
34
 
47
35
  function showToast(message) {
48
- if (!!message) {
49
- const toasts = document.querySelector('crowdin-toasts');
50
- if (toasts && toasts.pushToasts) {
51
- toasts.pushToasts([message]);
36
+ if (!!message) {
37
+ const toasts = document.querySelector('crowdin-toasts');
38
+ if (toasts && toasts.pushToasts) {
39
+ toasts.pushToasts([message]);
40
+ }
52
41
  }
53
- }
54
42
  }
55
43
 
56
44
  function catchRejection(e, message) {
57
- //session expired
58
- if (e.code && e.code === 401) {
59
- reloadLocation();
60
- return;
61
- }
62
- //payment required
63
- if (e.code && e.code === 402 && subscriptionModal) {
64
- subscriptionLink = e.message || message;
65
- subscriptionModal.open();
66
- return;
67
- }
68
- showToast(e.message || message);
45
+ //session expired
46
+ if (e.code && e.code === 401) {
47
+ reloadLocation();
48
+ return;
49
+ }
50
+ //payment required
51
+ if (e.code && e.code === 402 && subscriptionModal) {
52
+ subscriptionLink = e.message || message;
53
+ subscriptionModal.open();
54
+ return;
55
+ }
56
+ showToast(e.message || message);
69
57
  }
70
58
 
71
59
  function checkResponse(response) {
72
- return new Promise((resolve, reject) => {
73
- if (response.status === 204) {
74
- return resolve();
75
- }
76
- response
77
- .json()
78
- .then((res) => {
79
- if (![200, 201, 304].includes(response.status)) {
80
- reject(res);
81
- } else {
82
- if (res.message) {
83
- showToast(res.message);
84
- }
85
- resolve(res);
60
+ return new Promise((resolve, reject) => {
61
+ if (response.status === 204) {
62
+ return resolve();
86
63
  }
87
- })
88
- .catch((e) => {
89
- reject(e);
90
- });
91
- });
64
+ response
65
+ .json()
66
+ .then((res) => {
67
+ if (![200, 201, 304].includes(response.status)) {
68
+ reject(res);
69
+ } else {
70
+ if (res.message) {
71
+ showToast(res.message);
72
+ }
73
+ resolve(res);
74
+ }
75
+ })
76
+ .catch((e) => {
77
+ reject(e);
78
+ });
79
+ });
92
80
  }
93
81
 
94
82
  function checkOrigin() {
95
- return new Promise((resolve, reject) => {
96
- try {
97
- const tokenData = parseJwt(tokenJwt);
98
- if (tokenData.exp < parseInt(new Date().getTime() / 1000)) {
99
- // request for new token
100
- parentWindowPostMessage({
101
- identifier: frameData.app.identifier,
102
- key: frameData.app.key,
103
- client_id: clientId,
104
- command: 'token',
105
- uid: new Date().getTime(),
106
- data: {},
107
- })
108
- .then((eventData) => {
109
- restParams = `?origin=${origin}&client_id=${clientId}&tokenJwt=${eventData.tokenJwt}`;
83
+ return new Promise((resolve, reject) => {
84
+ AP.getJwtToken(jwtToken => {
85
+ restParams = `?origin=${origin}&client_id=${clientId}&jwtToken=${jwtToken}`;
110
86
  resolve(restParams);
111
- })
112
- .catch(() => reject());
113
- } else {
114
- resolve(restParams);
115
- }
116
- } catch (e) {
117
- reject();
118
- }
119
- });
120
- }
121
-
122
- function parseJwt(token) {
123
- const base64Url = token.split('.')[1];
124
- const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
125
- const jsonPayload = decodeURIComponent(
126
- atob(base64)
127
- .split('')
128
- .map(function (c) {
129
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
130
- })
131
- .join(''),
132
- );
133
- return JSON.parse(jsonPayload);
87
+ });
88
+ });
134
89
  }
135
90
 
136
91
  function reloadLocation() {
137
- window.location.href =
138
- window.location.protocol +
139
- '//' +
140
- window.location.host +
141
- window.location.pathname +
142
- restParams;
92
+ window.location.href =
93
+ window.location.protocol + '//' + window.location.host + window.location.pathname + restParams;
143
94
  }
@@ -105,7 +105,11 @@
105
105
  {{/ifeq}}
106
106
  {{/ifeq}}
107
107
  {{else}}
108
- <crowdin-p>{{label}}</crowdin-p>
108
+ {{#if labelHtml}}
109
+ <crowdin-p>{{{labelHtml}}}</crowdin-p>
110
+ {{else}}
111
+ <crowdin-p>{{label}}</crowdin-p>
112
+ {{/if}}
109
113
  {{/if}}
110
114
  <div style="padding: 8px"></div>
111
115
  {{/each}}
@@ -164,7 +164,11 @@
164
164
  </crowdin-input>
165
165
  {{/ifeq}}
166
166
  {{else}}
167
- <crowdin-p>{{label}}</crowdin-p>
167
+ {{#if labelHtml}}
168
+ <crowdin-p>{{labelHtml}}</crowdin-p>
169
+ {{else}}
170
+ <crowdin-p>{{label}}</crowdin-p>
171
+ {{/if}}
168
172
  {{/if}}
169
173
  <div style="padding: 8px"></div>
170
174
  {{/each}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.28.7",
3
+ "version": "0.28.9",
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"
14
14
  },
15
15
  "dependencies": {
16
- "@crowdin/crowdin-apps-functions": "0.4.0",
16
+ "@crowdin/crowdin-apps-functions": "0.5.1",
17
17
  "@types/pg": "^8.6.6",
18
18
  "amqplib": "^0.10.3",
19
19
  "crypto-js": "^4.0.0",
@@ -26,26 +26,26 @@
26
26
  "uuid": "^8.3.2"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/amqplib": "^0.10.1",
30
- "@babel/preset-react": "^7.18.6",
29
+ "@babel/preset-react": "^7.22.3",
31
30
  "@emotion/react": "^11.10.6",
32
31
  "@emotion/styled": "^11.10.6",
33
32
  "@mui/icons-material": "^5.11.16",
34
33
  "@mui/material": "^5.11.12",
35
- "@rjsf/core": "^5.2.0",
36
- "@rjsf/mui": "^5.2.0",
37
- "@rjsf/utils": "^5.6.2",
38
- "@rjsf/validator-ajv8": "^5.6.2",
34
+ "@rjsf/core": "^5.7.3",
35
+ "@rjsf/mui": "^5.7.3",
36
+ "@rjsf/utils": "^5.7.3",
37
+ "@rjsf/validator-ajv8": "^5.7.3",
39
38
  "@rollup/plugin-babel": "^6.0.3",
40
39
  "@rollup/plugin-commonjs": "^24.0.1",
41
40
  "@rollup/plugin-json": "^6.0.0",
42
41
  "@rollup/plugin-node-resolve": "^15.0.1",
43
42
  "@rollup/plugin-replace": "^5.0.2",
44
43
  "@rollup/plugin-terser": "^0.4.0",
44
+ "@types/amqplib": "^0.10.1",
45
45
  "@types/crypto-js": "^4.0.0",
46
46
  "@types/express": "4.17.17",
47
47
  "@types/express-handlebars": "^5.3.1",
48
- "@types/jest": "^29.5.1",
48
+ "@types/jest": "^29.5.2",
49
49
  "@types/node": "^12.20.55",
50
50
  "@types/node-cron": "^3.0.7",
51
51
  "@typescript-eslint/eslint-plugin": "^2.3.1",
@@ -59,7 +59,7 @@
59
59
  "react": "^18.2.0",
60
60
  "react-dom": "^18.2.0",
61
61
  "rollup": "^3.20.2",
62
- "ts-jest": "^29.0.5",
62
+ "ts-jest": "^29.1.0",
63
63
  "typescript": "^4.9.5"
64
64
  },
65
65
  "repository": {