@uniformdev/tms-phrase 19.165.2-alpha.0 → 19.167.2-alpha.3
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/dist/index.esm.js +25 -42
- package/dist/index.js +26 -43
- package/dist/index.mjs +25 -42
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
throw TypeError("Cannot " + msg);
|
|
4
|
-
};
|
|
5
|
-
var __privateGet = (obj, member, getter) => {
|
|
6
|
-
__accessCheck(obj, member, "read from private field");
|
|
7
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
-
};
|
|
9
|
-
var __privateAdd = (obj, member, value) => {
|
|
10
|
-
if (member.has(obj))
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
|
-
var __privateMethod = (obj, member, method) => {
|
|
20
|
-
__accessCheck(obj, member, "access private method");
|
|
21
|
-
return method;
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
22
3
|
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
23
9
|
|
|
24
10
|
// src/job.ts
|
|
25
11
|
var buildPhraseJobFileName = ({
|
|
@@ -59,20 +45,19 @@ var isGuid = (value) => {
|
|
|
59
45
|
import { v5 } from "uuid";
|
|
60
46
|
var EXPIRES_GAP = 5 * 60 * 1e3;
|
|
61
47
|
var AUTH_SESSION_STORAGE_KEY = "uniform_phrase_auth";
|
|
62
|
-
var _options, _authToken, _phraseApiFetcher,
|
|
48
|
+
var _options, _authToken, _phraseApiFetcher, _PhraseTmsClient_instances, ensureAuthToken_fn, login_fn;
|
|
63
49
|
var PhraseTmsClient = class {
|
|
64
50
|
constructor(options) {
|
|
65
|
-
__privateAdd(this,
|
|
66
|
-
__privateAdd(this,
|
|
67
|
-
__privateAdd(this,
|
|
68
|
-
__privateAdd(this,
|
|
69
|
-
__privateAdd(this, _phraseApiFetcher, void 0);
|
|
51
|
+
__privateAdd(this, _PhraseTmsClient_instances);
|
|
52
|
+
__privateAdd(this, _options);
|
|
53
|
+
__privateAdd(this, _authToken);
|
|
54
|
+
__privateAdd(this, _phraseApiFetcher);
|
|
70
55
|
__privateSet(this, _options, { ...options });
|
|
71
56
|
__privateSet(this, _phraseApiFetcher, options.proxyUrl ? createProxyPhraseApiFetcher(options.proxyUrl) : phraseApiFetcher);
|
|
72
57
|
}
|
|
73
58
|
async checkCredentials() {
|
|
74
59
|
try {
|
|
75
|
-
const authToken = await __privateMethod(this,
|
|
60
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
76
61
|
return !!authToken.token;
|
|
77
62
|
} catch (error) {
|
|
78
63
|
return false;
|
|
@@ -83,7 +68,7 @@ var PhraseTmsClient = class {
|
|
|
83
68
|
*/
|
|
84
69
|
async listProjects() {
|
|
85
70
|
var _a, _b, _c;
|
|
86
|
-
await __privateMethod(this,
|
|
71
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
87
72
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
88
73
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects`,
|
|
89
74
|
method: "GET",
|
|
@@ -97,7 +82,7 @@ var PhraseTmsClient = class {
|
|
|
97
82
|
if (!projectUid) {
|
|
98
83
|
throw new Error("missing projectUid");
|
|
99
84
|
}
|
|
100
|
-
await __privateMethod(this,
|
|
85
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
101
86
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
102
87
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}`,
|
|
103
88
|
method: "GET",
|
|
@@ -117,7 +102,7 @@ var PhraseTmsClient = class {
|
|
|
117
102
|
if (!projectUid) {
|
|
118
103
|
throw new Error("missing projectUid");
|
|
119
104
|
}
|
|
120
|
-
await __privateMethod(this,
|
|
105
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
121
106
|
const rawResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
122
107
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
123
108
|
method: "GET",
|
|
@@ -138,7 +123,7 @@ var PhraseTmsClient = class {
|
|
|
138
123
|
if (!importSettings) {
|
|
139
124
|
throw new Error("missing importSettings");
|
|
140
125
|
}
|
|
141
|
-
await __privateMethod(this,
|
|
126
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
142
127
|
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
143
128
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
144
129
|
method: "PUT",
|
|
@@ -153,7 +138,7 @@ var PhraseTmsClient = class {
|
|
|
153
138
|
if (!projectUid) {
|
|
154
139
|
throw new Error("missing projectUid");
|
|
155
140
|
}
|
|
156
|
-
await __privateMethod(this,
|
|
141
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
157
142
|
const { status = [], fileName = "" } = options != null ? options : {};
|
|
158
143
|
const apiUrl = new URL(`${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs`);
|
|
159
144
|
if (fileName) {
|
|
@@ -178,7 +163,7 @@ var PhraseTmsClient = class {
|
|
|
178
163
|
if (!projectUid) {
|
|
179
164
|
throw new Error("missing projectUid");
|
|
180
165
|
}
|
|
181
|
-
await __privateMethod(this,
|
|
166
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
182
167
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
183
168
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/providers`,
|
|
184
169
|
method: "GET",
|
|
@@ -200,7 +185,7 @@ var PhraseTmsClient = class {
|
|
|
200
185
|
if (!payload) {
|
|
201
186
|
throw new Error("missing payload");
|
|
202
187
|
}
|
|
203
|
-
await __privateMethod(this,
|
|
188
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
204
189
|
const fileName = buildPhraseJobFileName({
|
|
205
190
|
uniformProjectId: payload.metadata.uniformProjectId,
|
|
206
191
|
uniformEntityId: payload.metadata.entity.id,
|
|
@@ -250,7 +235,7 @@ var PhraseTmsClient = class {
|
|
|
250
235
|
if (!jobUid) {
|
|
251
236
|
throw new Error("missing jobUid");
|
|
252
237
|
}
|
|
253
|
-
await __privateMethod(this,
|
|
238
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
254
239
|
const rawAsyncRequestIdResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
255
240
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs/${jobUid}/targetFile`,
|
|
256
241
|
method: "PUT",
|
|
@@ -303,7 +288,7 @@ var PhraseTmsClient = class {
|
|
|
303
288
|
if (!jobStatus) {
|
|
304
289
|
throw new Error("missing jobStatus");
|
|
305
290
|
}
|
|
306
|
-
await __privateMethod(this,
|
|
291
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
307
292
|
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
308
293
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/jobs/${jobUid}/setStatus`,
|
|
309
294
|
method: "POST",
|
|
@@ -317,7 +302,7 @@ var PhraseTmsClient = class {
|
|
|
317
302
|
_options = new WeakMap();
|
|
318
303
|
_authToken = new WeakMap();
|
|
319
304
|
_phraseApiFetcher = new WeakMap();
|
|
320
|
-
|
|
305
|
+
_PhraseTmsClient_instances = new WeakSet();
|
|
321
306
|
ensureAuthToken_fn = async function() {
|
|
322
307
|
if (!__privateGet(this, _authToken)) {
|
|
323
308
|
const sessionToken = readSessionStorage(AUTH_SESSION_STORAGE_KEY);
|
|
@@ -327,7 +312,7 @@ ensureAuthToken_fn = async function() {
|
|
|
327
312
|
}
|
|
328
313
|
const isExpired = !__privateGet(this, _authToken) || __privateGet(this, _authToken).expires - EXPIRES_GAP <= Date.now();
|
|
329
314
|
if (isExpired) {
|
|
330
|
-
const authToken = await __privateMethod(this,
|
|
315
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
331
316
|
writeSessionStorage(AUTH_SESSION_STORAGE_KEY, {
|
|
332
317
|
hash: calculateSessionTokenHash(__privateGet(this, _options)),
|
|
333
318
|
authToken
|
|
@@ -335,7 +320,6 @@ ensureAuthToken_fn = async function() {
|
|
|
335
320
|
__privateSet(this, _authToken, authToken);
|
|
336
321
|
}
|
|
337
322
|
};
|
|
338
|
-
_login = new WeakSet();
|
|
339
323
|
login_fn = async function() {
|
|
340
324
|
var _a;
|
|
341
325
|
const { apiHost, userName, password } = __privateGet(this, _options);
|
|
@@ -433,8 +417,7 @@ var readSessionStorage = (key) => {
|
|
|
433
417
|
return null;
|
|
434
418
|
}
|
|
435
419
|
const data = sessionStorage.getItem(key);
|
|
436
|
-
if (!data)
|
|
437
|
-
return null;
|
|
420
|
+
if (!data) return null;
|
|
438
421
|
try {
|
|
439
422
|
return JSON.parse(data);
|
|
440
423
|
} catch (e) {
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
6
9
|
var __export = (target, all) => {
|
|
7
10
|
for (var name in all)
|
|
8
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,28 +19,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
18
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __accessCheck = (obj, member, msg) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
__accessCheck(obj, member, "read from private field");
|
|
25
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
26
|
-
};
|
|
27
|
-
var __privateAdd = (obj, member, value) => {
|
|
28
|
-
if (member.has(obj))
|
|
29
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
30
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
31
|
-
};
|
|
32
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
33
|
-
__accessCheck(obj, member, "write to private field");
|
|
34
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
|
-
var __privateMethod = (obj, member, method) => {
|
|
38
|
-
__accessCheck(obj, member, "access private method");
|
|
39
|
-
return method;
|
|
40
|
-
};
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
41
27
|
|
|
42
28
|
// src/index.ts
|
|
43
29
|
var src_exports = {};
|
|
@@ -86,20 +72,19 @@ var isGuid = (value) => {
|
|
|
86
72
|
var import_uuid = require("uuid");
|
|
87
73
|
var EXPIRES_GAP = 5 * 60 * 1e3;
|
|
88
74
|
var AUTH_SESSION_STORAGE_KEY = "uniform_phrase_auth";
|
|
89
|
-
var _options, _authToken, _phraseApiFetcher,
|
|
75
|
+
var _options, _authToken, _phraseApiFetcher, _PhraseTmsClient_instances, ensureAuthToken_fn, login_fn;
|
|
90
76
|
var PhraseTmsClient = class {
|
|
91
77
|
constructor(options) {
|
|
92
|
-
__privateAdd(this,
|
|
93
|
-
__privateAdd(this,
|
|
94
|
-
__privateAdd(this,
|
|
95
|
-
__privateAdd(this,
|
|
96
|
-
__privateAdd(this, _phraseApiFetcher, void 0);
|
|
78
|
+
__privateAdd(this, _PhraseTmsClient_instances);
|
|
79
|
+
__privateAdd(this, _options);
|
|
80
|
+
__privateAdd(this, _authToken);
|
|
81
|
+
__privateAdd(this, _phraseApiFetcher);
|
|
97
82
|
__privateSet(this, _options, { ...options });
|
|
98
83
|
__privateSet(this, _phraseApiFetcher, options.proxyUrl ? createProxyPhraseApiFetcher(options.proxyUrl) : phraseApiFetcher);
|
|
99
84
|
}
|
|
100
85
|
async checkCredentials() {
|
|
101
86
|
try {
|
|
102
|
-
const authToken = await __privateMethod(this,
|
|
87
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
103
88
|
return !!authToken.token;
|
|
104
89
|
} catch (error) {
|
|
105
90
|
return false;
|
|
@@ -110,7 +95,7 @@ var PhraseTmsClient = class {
|
|
|
110
95
|
*/
|
|
111
96
|
async listProjects() {
|
|
112
97
|
var _a, _b, _c;
|
|
113
|
-
await __privateMethod(this,
|
|
98
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
114
99
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
115
100
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects`,
|
|
116
101
|
method: "GET",
|
|
@@ -124,7 +109,7 @@ var PhraseTmsClient = class {
|
|
|
124
109
|
if (!projectUid) {
|
|
125
110
|
throw new Error("missing projectUid");
|
|
126
111
|
}
|
|
127
|
-
await __privateMethod(this,
|
|
112
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
128
113
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
129
114
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}`,
|
|
130
115
|
method: "GET",
|
|
@@ -144,7 +129,7 @@ var PhraseTmsClient = class {
|
|
|
144
129
|
if (!projectUid) {
|
|
145
130
|
throw new Error("missing projectUid");
|
|
146
131
|
}
|
|
147
|
-
await __privateMethod(this,
|
|
132
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
148
133
|
const rawResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
149
134
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
150
135
|
method: "GET",
|
|
@@ -165,7 +150,7 @@ var PhraseTmsClient = class {
|
|
|
165
150
|
if (!importSettings) {
|
|
166
151
|
throw new Error("missing importSettings");
|
|
167
152
|
}
|
|
168
|
-
await __privateMethod(this,
|
|
153
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
169
154
|
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
170
155
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
171
156
|
method: "PUT",
|
|
@@ -180,7 +165,7 @@ var PhraseTmsClient = class {
|
|
|
180
165
|
if (!projectUid) {
|
|
181
166
|
throw new Error("missing projectUid");
|
|
182
167
|
}
|
|
183
|
-
await __privateMethod(this,
|
|
168
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
184
169
|
const { status = [], fileName = "" } = options != null ? options : {};
|
|
185
170
|
const apiUrl = new URL(`${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs`);
|
|
186
171
|
if (fileName) {
|
|
@@ -205,7 +190,7 @@ var PhraseTmsClient = class {
|
|
|
205
190
|
if (!projectUid) {
|
|
206
191
|
throw new Error("missing projectUid");
|
|
207
192
|
}
|
|
208
|
-
await __privateMethod(this,
|
|
193
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
209
194
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
210
195
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/providers`,
|
|
211
196
|
method: "GET",
|
|
@@ -227,7 +212,7 @@ var PhraseTmsClient = class {
|
|
|
227
212
|
if (!payload) {
|
|
228
213
|
throw new Error("missing payload");
|
|
229
214
|
}
|
|
230
|
-
await __privateMethod(this,
|
|
215
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
231
216
|
const fileName = buildPhraseJobFileName({
|
|
232
217
|
uniformProjectId: payload.metadata.uniformProjectId,
|
|
233
218
|
uniformEntityId: payload.metadata.entity.id,
|
|
@@ -277,7 +262,7 @@ var PhraseTmsClient = class {
|
|
|
277
262
|
if (!jobUid) {
|
|
278
263
|
throw new Error("missing jobUid");
|
|
279
264
|
}
|
|
280
|
-
await __privateMethod(this,
|
|
265
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
281
266
|
const rawAsyncRequestIdResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
282
267
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs/${jobUid}/targetFile`,
|
|
283
268
|
method: "PUT",
|
|
@@ -330,7 +315,7 @@ var PhraseTmsClient = class {
|
|
|
330
315
|
if (!jobStatus) {
|
|
331
316
|
throw new Error("missing jobStatus");
|
|
332
317
|
}
|
|
333
|
-
await __privateMethod(this,
|
|
318
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
334
319
|
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
335
320
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/jobs/${jobUid}/setStatus`,
|
|
336
321
|
method: "POST",
|
|
@@ -344,7 +329,7 @@ var PhraseTmsClient = class {
|
|
|
344
329
|
_options = new WeakMap();
|
|
345
330
|
_authToken = new WeakMap();
|
|
346
331
|
_phraseApiFetcher = new WeakMap();
|
|
347
|
-
|
|
332
|
+
_PhraseTmsClient_instances = new WeakSet();
|
|
348
333
|
ensureAuthToken_fn = async function() {
|
|
349
334
|
if (!__privateGet(this, _authToken)) {
|
|
350
335
|
const sessionToken = readSessionStorage(AUTH_SESSION_STORAGE_KEY);
|
|
@@ -354,7 +339,7 @@ ensureAuthToken_fn = async function() {
|
|
|
354
339
|
}
|
|
355
340
|
const isExpired = !__privateGet(this, _authToken) || __privateGet(this, _authToken).expires - EXPIRES_GAP <= Date.now();
|
|
356
341
|
if (isExpired) {
|
|
357
|
-
const authToken = await __privateMethod(this,
|
|
342
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
358
343
|
writeSessionStorage(AUTH_SESSION_STORAGE_KEY, {
|
|
359
344
|
hash: calculateSessionTokenHash(__privateGet(this, _options)),
|
|
360
345
|
authToken
|
|
@@ -362,7 +347,6 @@ ensureAuthToken_fn = async function() {
|
|
|
362
347
|
__privateSet(this, _authToken, authToken);
|
|
363
348
|
}
|
|
364
349
|
};
|
|
365
|
-
_login = new WeakSet();
|
|
366
350
|
login_fn = async function() {
|
|
367
351
|
var _a;
|
|
368
352
|
const { apiHost, userName, password } = __privateGet(this, _options);
|
|
@@ -460,8 +444,7 @@ var readSessionStorage = (key) => {
|
|
|
460
444
|
return null;
|
|
461
445
|
}
|
|
462
446
|
const data = sessionStorage.getItem(key);
|
|
463
|
-
if (!data)
|
|
464
|
-
return null;
|
|
447
|
+
if (!data) return null;
|
|
465
448
|
try {
|
|
466
449
|
return JSON.parse(data);
|
|
467
450
|
} catch (e) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
throw TypeError("Cannot " + msg);
|
|
4
|
-
};
|
|
5
|
-
var __privateGet = (obj, member, getter) => {
|
|
6
|
-
__accessCheck(obj, member, "read from private field");
|
|
7
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
-
};
|
|
9
|
-
var __privateAdd = (obj, member, value) => {
|
|
10
|
-
if (member.has(obj))
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
|
-
var __privateMethod = (obj, member, method) => {
|
|
20
|
-
__accessCheck(obj, member, "access private method");
|
|
21
|
-
return method;
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
22
3
|
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
23
9
|
|
|
24
10
|
// src/job.ts
|
|
25
11
|
var buildPhraseJobFileName = ({
|
|
@@ -59,20 +45,19 @@ var isGuid = (value) => {
|
|
|
59
45
|
import { v5 } from "uuid";
|
|
60
46
|
var EXPIRES_GAP = 5 * 60 * 1e3;
|
|
61
47
|
var AUTH_SESSION_STORAGE_KEY = "uniform_phrase_auth";
|
|
62
|
-
var _options, _authToken, _phraseApiFetcher,
|
|
48
|
+
var _options, _authToken, _phraseApiFetcher, _PhraseTmsClient_instances, ensureAuthToken_fn, login_fn;
|
|
63
49
|
var PhraseTmsClient = class {
|
|
64
50
|
constructor(options) {
|
|
65
|
-
__privateAdd(this,
|
|
66
|
-
__privateAdd(this,
|
|
67
|
-
__privateAdd(this,
|
|
68
|
-
__privateAdd(this,
|
|
69
|
-
__privateAdd(this, _phraseApiFetcher, void 0);
|
|
51
|
+
__privateAdd(this, _PhraseTmsClient_instances);
|
|
52
|
+
__privateAdd(this, _options);
|
|
53
|
+
__privateAdd(this, _authToken);
|
|
54
|
+
__privateAdd(this, _phraseApiFetcher);
|
|
70
55
|
__privateSet(this, _options, { ...options });
|
|
71
56
|
__privateSet(this, _phraseApiFetcher, options.proxyUrl ? createProxyPhraseApiFetcher(options.proxyUrl) : phraseApiFetcher);
|
|
72
57
|
}
|
|
73
58
|
async checkCredentials() {
|
|
74
59
|
try {
|
|
75
|
-
const authToken = await __privateMethod(this,
|
|
60
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
76
61
|
return !!authToken.token;
|
|
77
62
|
} catch (error) {
|
|
78
63
|
return false;
|
|
@@ -83,7 +68,7 @@ var PhraseTmsClient = class {
|
|
|
83
68
|
*/
|
|
84
69
|
async listProjects() {
|
|
85
70
|
var _a, _b, _c;
|
|
86
|
-
await __privateMethod(this,
|
|
71
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
87
72
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
88
73
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects`,
|
|
89
74
|
method: "GET",
|
|
@@ -97,7 +82,7 @@ var PhraseTmsClient = class {
|
|
|
97
82
|
if (!projectUid) {
|
|
98
83
|
throw new Error("missing projectUid");
|
|
99
84
|
}
|
|
100
|
-
await __privateMethod(this,
|
|
85
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
101
86
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
102
87
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}`,
|
|
103
88
|
method: "GET",
|
|
@@ -117,7 +102,7 @@ var PhraseTmsClient = class {
|
|
|
117
102
|
if (!projectUid) {
|
|
118
103
|
throw new Error("missing projectUid");
|
|
119
104
|
}
|
|
120
|
-
await __privateMethod(this,
|
|
105
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
121
106
|
const rawResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
122
107
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
123
108
|
method: "GET",
|
|
@@ -138,7 +123,7 @@ var PhraseTmsClient = class {
|
|
|
138
123
|
if (!importSettings) {
|
|
139
124
|
throw new Error("missing importSettings");
|
|
140
125
|
}
|
|
141
|
-
await __privateMethod(this,
|
|
126
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
142
127
|
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
143
128
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
144
129
|
method: "PUT",
|
|
@@ -153,7 +138,7 @@ var PhraseTmsClient = class {
|
|
|
153
138
|
if (!projectUid) {
|
|
154
139
|
throw new Error("missing projectUid");
|
|
155
140
|
}
|
|
156
|
-
await __privateMethod(this,
|
|
141
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
157
142
|
const { status = [], fileName = "" } = options != null ? options : {};
|
|
158
143
|
const apiUrl = new URL(`${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs`);
|
|
159
144
|
if (fileName) {
|
|
@@ -178,7 +163,7 @@ var PhraseTmsClient = class {
|
|
|
178
163
|
if (!projectUid) {
|
|
179
164
|
throw new Error("missing projectUid");
|
|
180
165
|
}
|
|
181
|
-
await __privateMethod(this,
|
|
166
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
182
167
|
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
183
168
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/providers`,
|
|
184
169
|
method: "GET",
|
|
@@ -200,7 +185,7 @@ var PhraseTmsClient = class {
|
|
|
200
185
|
if (!payload) {
|
|
201
186
|
throw new Error("missing payload");
|
|
202
187
|
}
|
|
203
|
-
await __privateMethod(this,
|
|
188
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
204
189
|
const fileName = buildPhraseJobFileName({
|
|
205
190
|
uniformProjectId: payload.metadata.uniformProjectId,
|
|
206
191
|
uniformEntityId: payload.metadata.entity.id,
|
|
@@ -250,7 +235,7 @@ var PhraseTmsClient = class {
|
|
|
250
235
|
if (!jobUid) {
|
|
251
236
|
throw new Error("missing jobUid");
|
|
252
237
|
}
|
|
253
|
-
await __privateMethod(this,
|
|
238
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
254
239
|
const rawAsyncRequestIdResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
255
240
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs/${jobUid}/targetFile`,
|
|
256
241
|
method: "PUT",
|
|
@@ -303,7 +288,7 @@ var PhraseTmsClient = class {
|
|
|
303
288
|
if (!jobStatus) {
|
|
304
289
|
throw new Error("missing jobStatus");
|
|
305
290
|
}
|
|
306
|
-
await __privateMethod(this,
|
|
291
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
307
292
|
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
308
293
|
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/jobs/${jobUid}/setStatus`,
|
|
309
294
|
method: "POST",
|
|
@@ -317,7 +302,7 @@ var PhraseTmsClient = class {
|
|
|
317
302
|
_options = new WeakMap();
|
|
318
303
|
_authToken = new WeakMap();
|
|
319
304
|
_phraseApiFetcher = new WeakMap();
|
|
320
|
-
|
|
305
|
+
_PhraseTmsClient_instances = new WeakSet();
|
|
321
306
|
ensureAuthToken_fn = async function() {
|
|
322
307
|
if (!__privateGet(this, _authToken)) {
|
|
323
308
|
const sessionToken = readSessionStorage(AUTH_SESSION_STORAGE_KEY);
|
|
@@ -327,7 +312,7 @@ ensureAuthToken_fn = async function() {
|
|
|
327
312
|
}
|
|
328
313
|
const isExpired = !__privateGet(this, _authToken) || __privateGet(this, _authToken).expires - EXPIRES_GAP <= Date.now();
|
|
329
314
|
if (isExpired) {
|
|
330
|
-
const authToken = await __privateMethod(this,
|
|
315
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
331
316
|
writeSessionStorage(AUTH_SESSION_STORAGE_KEY, {
|
|
332
317
|
hash: calculateSessionTokenHash(__privateGet(this, _options)),
|
|
333
318
|
authToken
|
|
@@ -335,7 +320,6 @@ ensureAuthToken_fn = async function() {
|
|
|
335
320
|
__privateSet(this, _authToken, authToken);
|
|
336
321
|
}
|
|
337
322
|
};
|
|
338
|
-
_login = new WeakSet();
|
|
339
323
|
login_fn = async function() {
|
|
340
324
|
var _a;
|
|
341
325
|
const { apiHost, userName, password } = __privateGet(this, _options);
|
|
@@ -433,8 +417,7 @@ var readSessionStorage = (key) => {
|
|
|
433
417
|
return null;
|
|
434
418
|
}
|
|
435
419
|
const data = sessionStorage.getItem(key);
|
|
436
|
-
if (!data)
|
|
437
|
-
return null;
|
|
420
|
+
if (!data) return null;
|
|
438
421
|
try {
|
|
439
422
|
return JSON.parse(data);
|
|
440
423
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/tms-phrase",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.167.2-alpha.3+d42f32a982",
|
|
4
4
|
"description": "Uniform Phrase TMS SDK",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@uniformdev/tms-sdk": "19.
|
|
36
|
+
"@uniformdev/tms-sdk": "19.167.2-alpha.3+d42f32a982",
|
|
37
37
|
"uuid": "9.0.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/uuid": "9.0.4"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "d42f32a98294c96f55a29c10c7c461c5327f56f3"
|
|
43
43
|
}
|