@uniformdev/tms-phrase 19.135.1-alpha.11
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/LICENSE.txt +2 -0
- package/dist/index.d.mts +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.esm.js +432 -0
- package/dist/index.js +460 -0
- package/dist/index.mjs +432 -0
- package/package.json +43 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
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);
|
|
9
|
+
|
|
10
|
+
// src/job.ts
|
|
11
|
+
var buildPhraseJobFileName = ({
|
|
12
|
+
uniformProjectId,
|
|
13
|
+
uniformEntityId,
|
|
14
|
+
prefix
|
|
15
|
+
}) => {
|
|
16
|
+
if (!isGuid(uniformProjectId) || !isGuid(uniformEntityId)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return `${prefix ? `${prefix}_` : ""}${uniformProjectId}_${uniformEntityId}.json`;
|
|
20
|
+
};
|
|
21
|
+
var parsePhraseJobFileName = (jobFileName) => {
|
|
22
|
+
if (!jobFileName || !jobFileName.endsWith(".json")) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const withoutExt = jobFileName.slice(0, -1 * ".json".length);
|
|
26
|
+
const segments = withoutExt.split("_").filter((x) => !!x);
|
|
27
|
+
if (segments.length < 2) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const uniformProjectId = segments[segments.length - 2];
|
|
31
|
+
const uniformEntityId = segments[segments.length - 1];
|
|
32
|
+
if (!isGuid(uniformProjectId) || !isGuid(uniformEntityId)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
uniformProjectId,
|
|
37
|
+
uniformEntityId
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var isGuid = (value) => {
|
|
41
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/PhraseTmsClient.ts
|
|
45
|
+
import { v5 } from "uuid";
|
|
46
|
+
var EXPIRES_GAP = 5 * 60 * 1e3;
|
|
47
|
+
var AUTH_SESSION_STORAGE_KEY = "uniform_phrase_auth";
|
|
48
|
+
var _options, _authToken, _phraseApiFetcher, _PhraseTmsClient_instances, ensureAuthToken_fn, login_fn;
|
|
49
|
+
var PhraseTmsClient = class {
|
|
50
|
+
constructor(options) {
|
|
51
|
+
__privateAdd(this, _PhraseTmsClient_instances);
|
|
52
|
+
__privateAdd(this, _options);
|
|
53
|
+
__privateAdd(this, _authToken);
|
|
54
|
+
__privateAdd(this, _phraseApiFetcher);
|
|
55
|
+
__privateSet(this, _options, { ...options });
|
|
56
|
+
__privateSet(this, _phraseApiFetcher, options.proxyUrl ? createProxyPhraseApiFetcher(options.proxyUrl) : phraseApiFetcher);
|
|
57
|
+
}
|
|
58
|
+
async checkCredentials() {
|
|
59
|
+
try {
|
|
60
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
61
|
+
return !!authToken.token;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* https://cloud.memsource.com/web/docs/api#operation/listProjects
|
|
68
|
+
*/
|
|
69
|
+
async listProjects() {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
72
|
+
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
73
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects`,
|
|
74
|
+
method: "GET",
|
|
75
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token
|
|
76
|
+
});
|
|
77
|
+
const json = (_b = await response.json()) != null ? _b : {};
|
|
78
|
+
return (_c = json.content) != null ? _c : [];
|
|
79
|
+
}
|
|
80
|
+
async getProject(projectUid) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (!projectUid) {
|
|
83
|
+
throw new Error("missing projectUid");
|
|
84
|
+
}
|
|
85
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
86
|
+
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
87
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}`,
|
|
88
|
+
method: "GET",
|
|
89
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token
|
|
90
|
+
});
|
|
91
|
+
if (response.status === 404) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const json = (_b = await response.json()) != null ? _b : {};
|
|
95
|
+
return json.uid ? json : null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* https://cloud.memsource.com/web/docs/api#operation/getImportSettingsForProject
|
|
99
|
+
*/
|
|
100
|
+
async getProjectFileImportSettings(projectUid) {
|
|
101
|
+
var _a;
|
|
102
|
+
if (!projectUid) {
|
|
103
|
+
throw new Error("missing projectUid");
|
|
104
|
+
}
|
|
105
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
106
|
+
const rawResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
107
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
108
|
+
method: "GET",
|
|
109
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token
|
|
110
|
+
});
|
|
111
|
+
try {
|
|
112
|
+
const json = await rawResponse.json();
|
|
113
|
+
return json ? json : null;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async setProjectFileImportSettings(projectUid, importSettings) {
|
|
119
|
+
var _a;
|
|
120
|
+
if (!projectUid) {
|
|
121
|
+
throw new Error("missing projectUid");
|
|
122
|
+
}
|
|
123
|
+
if (!importSettings) {
|
|
124
|
+
throw new Error("missing importSettings");
|
|
125
|
+
}
|
|
126
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
127
|
+
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
128
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/importSettings`,
|
|
129
|
+
method: "PUT",
|
|
130
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token,
|
|
131
|
+
body: importSettings
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* https://cloud.memsource.com/web/docs/api#operation/listPartsV2
|
|
136
|
+
*/
|
|
137
|
+
async listProjectJobs(projectUid, options) {
|
|
138
|
+
if (!projectUid) {
|
|
139
|
+
throw new Error("missing projectUid");
|
|
140
|
+
}
|
|
141
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
142
|
+
const { status = [], fileName = "" } = options != null ? options : {};
|
|
143
|
+
const apiUrl = new URL(`${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs`);
|
|
144
|
+
if (fileName) {
|
|
145
|
+
apiUrl.searchParams.set("filename", fileName);
|
|
146
|
+
}
|
|
147
|
+
if (status.length) {
|
|
148
|
+
status.forEach((x) => apiUrl.searchParams.append("status", x));
|
|
149
|
+
}
|
|
150
|
+
const jobs = await fetchAllPages(apiUrl.toString(), async (pageUrl) => {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
153
|
+
phraseApiUrl: pageUrl,
|
|
154
|
+
method: "GET",
|
|
155
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token
|
|
156
|
+
});
|
|
157
|
+
return (_b = await response.json()) != null ? _b : {};
|
|
158
|
+
});
|
|
159
|
+
return jobs;
|
|
160
|
+
}
|
|
161
|
+
async listProjectProviders(projectUid) {
|
|
162
|
+
var _a, _b, _c;
|
|
163
|
+
if (!projectUid) {
|
|
164
|
+
throw new Error("missing projectUid");
|
|
165
|
+
}
|
|
166
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
167
|
+
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
168
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/providers`,
|
|
169
|
+
method: "GET",
|
|
170
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token
|
|
171
|
+
});
|
|
172
|
+
const json = (_b = await response.json()) != null ? _b : {};
|
|
173
|
+
return (_c = json.content) != null ? _c : [];
|
|
174
|
+
}
|
|
175
|
+
async createTranslationJobFromPayload({
|
|
176
|
+
projectUid,
|
|
177
|
+
dueDate,
|
|
178
|
+
provider,
|
|
179
|
+
payload
|
|
180
|
+
}) {
|
|
181
|
+
var _a, _b, _c, _d;
|
|
182
|
+
if (!projectUid) {
|
|
183
|
+
throw new Error("missing projectUid");
|
|
184
|
+
}
|
|
185
|
+
if (!payload) {
|
|
186
|
+
throw new Error("missing payload");
|
|
187
|
+
}
|
|
188
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
189
|
+
const fileName = buildPhraseJobFileName({
|
|
190
|
+
uniformProjectId: payload.metadata.uniformProjectId,
|
|
191
|
+
uniformEntityId: payload.metadata.entity.id,
|
|
192
|
+
prefix: payload.metadata.entity.slug
|
|
193
|
+
});
|
|
194
|
+
if (!fileName) {
|
|
195
|
+
throw new Error("could not build job file name");
|
|
196
|
+
}
|
|
197
|
+
const rawCreateJobResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
198
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/jobs`,
|
|
199
|
+
method: "POST",
|
|
200
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token,
|
|
201
|
+
headers: {
|
|
202
|
+
"Content-Type": "application/octet-stream",
|
|
203
|
+
"Content-Disposition": `attachment; filename="${fileName}"`,
|
|
204
|
+
Memsource: JSON.stringify({
|
|
205
|
+
targetLangs: [payload.metadata.targetLang],
|
|
206
|
+
due: dueDate,
|
|
207
|
+
assignments: provider ? [
|
|
208
|
+
{
|
|
209
|
+
targetLang: payload.metadata.targetLang,
|
|
210
|
+
providers: [{ id: provider.id, type: provider.type }]
|
|
211
|
+
}
|
|
212
|
+
] : void 0,
|
|
213
|
+
useProjectFileImportSettings: true
|
|
214
|
+
// now we push real payload on job creation,
|
|
215
|
+
// so `preTranslate` can be configured in Phrase project settings (`Pre-translate on job creation`)
|
|
216
|
+
// preTranslate: true,
|
|
217
|
+
})
|
|
218
|
+
},
|
|
219
|
+
body: payload
|
|
220
|
+
});
|
|
221
|
+
const createJobResponse = (_b = await rawCreateJobResponse.json()) != null ? _b : {};
|
|
222
|
+
const jobUid = (_d = (_c = createJobResponse.jobs) == null ? void 0 : _c.at(0)) == null ? void 0 : _d.uid;
|
|
223
|
+
return jobUid ? jobUid : null;
|
|
224
|
+
}
|
|
225
|
+
async downloadTargetFile({
|
|
226
|
+
projectUid,
|
|
227
|
+
jobUid,
|
|
228
|
+
getAsyncRequestMaxAttempts = 10,
|
|
229
|
+
getAsyncRequestDelayMs = 500
|
|
230
|
+
}) {
|
|
231
|
+
var _a, _b, _c, _d, _e, _f;
|
|
232
|
+
if (!projectUid) {
|
|
233
|
+
throw new Error("missing projectUid");
|
|
234
|
+
}
|
|
235
|
+
if (!jobUid) {
|
|
236
|
+
throw new Error("missing jobUid");
|
|
237
|
+
}
|
|
238
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
239
|
+
const rawAsyncRequestIdResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
240
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs/${jobUid}/targetFile`,
|
|
241
|
+
method: "PUT",
|
|
242
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token
|
|
243
|
+
});
|
|
244
|
+
const asyncRequestIdResponse = (_b = await rawAsyncRequestIdResponse.json()) != null ? _b : {};
|
|
245
|
+
const asyncRequestId = (_c = asyncRequestIdResponse == null ? void 0 : asyncRequestIdResponse.asyncRequest) == null ? void 0 : _c.id;
|
|
246
|
+
if (!asyncRequestId) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
let attempts = 0;
|
|
250
|
+
while (attempts < getAsyncRequestMaxAttempts) {
|
|
251
|
+
attempts++;
|
|
252
|
+
const rawAsyncStatusResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
253
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/async/${asyncRequestId}`,
|
|
254
|
+
method: "GET",
|
|
255
|
+
apiToken: (_d = __privateGet(this, _authToken)) == null ? void 0 : _d.token
|
|
256
|
+
});
|
|
257
|
+
const asyncStatusResponse = (_e = await rawAsyncStatusResponse.json()) != null ? _e : {};
|
|
258
|
+
if (!asyncStatusResponse.asyncResponse) {
|
|
259
|
+
await new Promise((r) => setTimeout(r, getAsyncRequestDelayMs));
|
|
260
|
+
} else {
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const rawFileResponse = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
265
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v2/projects/${projectUid}/jobs/${jobUid}/downloadTargetFile/${asyncRequestId}`,
|
|
266
|
+
method: "GET",
|
|
267
|
+
apiToken: (_f = __privateGet(this, _authToken)) == null ? void 0 : _f.token
|
|
268
|
+
});
|
|
269
|
+
try {
|
|
270
|
+
const json = await rawFileResponse.json();
|
|
271
|
+
return json ? json : null;
|
|
272
|
+
} catch (e) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async setJobStatus({
|
|
277
|
+
projectUid,
|
|
278
|
+
jobUid,
|
|
279
|
+
jobStatus
|
|
280
|
+
}) {
|
|
281
|
+
var _a;
|
|
282
|
+
if (!projectUid) {
|
|
283
|
+
throw new Error("missing projectUid");
|
|
284
|
+
}
|
|
285
|
+
if (!jobUid) {
|
|
286
|
+
throw new Error("missing jobUid");
|
|
287
|
+
}
|
|
288
|
+
if (!jobStatus) {
|
|
289
|
+
throw new Error("missing jobStatus");
|
|
290
|
+
}
|
|
291
|
+
await __privateMethod(this, _PhraseTmsClient_instances, ensureAuthToken_fn).call(this);
|
|
292
|
+
await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
293
|
+
phraseApiUrl: `${__privateGet(this, _options).apiHost}/web/api2/v1/projects/${projectUid}/jobs/${jobUid}/setStatus`,
|
|
294
|
+
method: "POST",
|
|
295
|
+
apiToken: (_a = __privateGet(this, _authToken)) == null ? void 0 : _a.token,
|
|
296
|
+
body: {
|
|
297
|
+
requestedStatus: jobStatus
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
_options = new WeakMap();
|
|
303
|
+
_authToken = new WeakMap();
|
|
304
|
+
_phraseApiFetcher = new WeakMap();
|
|
305
|
+
_PhraseTmsClient_instances = new WeakSet();
|
|
306
|
+
ensureAuthToken_fn = async function() {
|
|
307
|
+
if (!__privateGet(this, _authToken)) {
|
|
308
|
+
const sessionToken = readSessionStorage(AUTH_SESSION_STORAGE_KEY);
|
|
309
|
+
if ((sessionToken == null ? void 0 : sessionToken.authToken) && sessionToken.hash === calculateSessionTokenHash(__privateGet(this, _options))) {
|
|
310
|
+
__privateSet(this, _authToken, sessionToken.authToken);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const isExpired = !__privateGet(this, _authToken) || __privateGet(this, _authToken).expires - EXPIRES_GAP <= Date.now();
|
|
314
|
+
if (isExpired) {
|
|
315
|
+
const authToken = await __privateMethod(this, _PhraseTmsClient_instances, login_fn).call(this);
|
|
316
|
+
writeSessionStorage(AUTH_SESSION_STORAGE_KEY, {
|
|
317
|
+
hash: calculateSessionTokenHash(__privateGet(this, _options)),
|
|
318
|
+
authToken
|
|
319
|
+
});
|
|
320
|
+
__privateSet(this, _authToken, authToken);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
login_fn = async function() {
|
|
324
|
+
var _a;
|
|
325
|
+
const { apiHost, userName, password } = __privateGet(this, _options);
|
|
326
|
+
if (!apiHost) {
|
|
327
|
+
throw new Error("missing apiHost");
|
|
328
|
+
}
|
|
329
|
+
if (!userName) {
|
|
330
|
+
throw new Error("missing userName");
|
|
331
|
+
}
|
|
332
|
+
if (!password) {
|
|
333
|
+
throw new Error("missing password");
|
|
334
|
+
}
|
|
335
|
+
const response = await __privateGet(this, _phraseApiFetcher).call(this, {
|
|
336
|
+
phraseApiUrl: `${apiHost}/web/api2/v3/auth/login`,
|
|
337
|
+
method: "POST",
|
|
338
|
+
body: {
|
|
339
|
+
userName,
|
|
340
|
+
password
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
const json = (_a = await response.json()) != null ? _a : {};
|
|
344
|
+
if (!response.ok) {
|
|
345
|
+
throw new Error("Invalid credentials");
|
|
346
|
+
}
|
|
347
|
+
const { token, expires } = json;
|
|
348
|
+
if (!token || !expires) {
|
|
349
|
+
throw new Error("Unknown login API response");
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
token,
|
|
353
|
+
expires: new Date(expires).getTime()
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
var fetchAllPages = async (initialApiUrl, fetchPage) => {
|
|
357
|
+
const content = [];
|
|
358
|
+
const initialPage = await fetchPage(initialApiUrl);
|
|
359
|
+
content.push(...initialPage.content);
|
|
360
|
+
const totalPages = initialPage.totalPages;
|
|
361
|
+
if (totalPages > 1) {
|
|
362
|
+
const promises = [];
|
|
363
|
+
for (let i = 1; i < totalPages; i++) {
|
|
364
|
+
const apiUrl = new URL(initialApiUrl);
|
|
365
|
+
apiUrl.searchParams.set("pageNumber", String(i));
|
|
366
|
+
promises.push(fetchPage(apiUrl.toString()));
|
|
367
|
+
}
|
|
368
|
+
(await Promise.all(promises)).forEach((page) => {
|
|
369
|
+
content.push(...page.content);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return content;
|
|
373
|
+
};
|
|
374
|
+
var phraseApiFetcher = async (payload) => {
|
|
375
|
+
const { phraseApiUrl, method, body, headers, apiToken } = payload;
|
|
376
|
+
const finalHeaders = headers != null ? headers : {};
|
|
377
|
+
if (apiToken) {
|
|
378
|
+
finalHeaders["Authorization"] = `ApiToken ${apiToken}`;
|
|
379
|
+
}
|
|
380
|
+
if (body) {
|
|
381
|
+
finalHeaders["Content-Type"] = finalHeaders["Content-Type"] || "application/json";
|
|
382
|
+
}
|
|
383
|
+
const response = await fetch(phraseApiUrl, {
|
|
384
|
+
method,
|
|
385
|
+
headers: Object.keys(finalHeaders).length ? finalHeaders : void 0,
|
|
386
|
+
body: body ? JSON.stringify(body, null, 2) : void 0
|
|
387
|
+
});
|
|
388
|
+
return response;
|
|
389
|
+
};
|
|
390
|
+
var createProxyPhraseApiFetcher = (proxyUrl) => {
|
|
391
|
+
return async (payload) => {
|
|
392
|
+
const response = await fetch(proxyUrl, {
|
|
393
|
+
method: "POST",
|
|
394
|
+
headers: {
|
|
395
|
+
"Content-Type": "application/json"
|
|
396
|
+
},
|
|
397
|
+
body: JSON.stringify(payload)
|
|
398
|
+
});
|
|
399
|
+
return response;
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
var calculateSessionTokenHash = ({
|
|
403
|
+
apiHost,
|
|
404
|
+
userName,
|
|
405
|
+
password
|
|
406
|
+
}) => {
|
|
407
|
+
const NAMESPACE = "a75447fe-9cca-47fe-b4b2-0a21fa96cd88";
|
|
408
|
+
return v5(JSON.stringify({ apiHost, userName, password }), NAMESPACE);
|
|
409
|
+
};
|
|
410
|
+
var writeSessionStorage = (key, value) => {
|
|
411
|
+
if (isSessionStorageSupported()) {
|
|
412
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
var readSessionStorage = (key) => {
|
|
416
|
+
if (!isSessionStorageSupported()) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
const data = sessionStorage.getItem(key);
|
|
420
|
+
if (!data) return null;
|
|
421
|
+
try {
|
|
422
|
+
return JSON.parse(data);
|
|
423
|
+
} catch (e) {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
var isSessionStorageSupported = () => typeof window !== "undefined" && typeof window.sessionStorage !== "undefined";
|
|
428
|
+
export {
|
|
429
|
+
PhraseTmsClient,
|
|
430
|
+
buildPhraseJobFileName,
|
|
431
|
+
parsePhraseJobFileName
|
|
432
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniformdev/tms-phrase",
|
|
3
|
+
"version": "19.135.1-alpha.11+9f52e6cfd6",
|
|
4
|
+
"description": "Uniform Phrase TMS SDK",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.esm.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"node": "./dist/index.mjs",
|
|
12
|
+
"default": "./dist/index.esm.js"
|
|
13
|
+
},
|
|
14
|
+
"require": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "run-s build:ts",
|
|
20
|
+
"build:ts": "tsup",
|
|
21
|
+
"dev": "run-s dev:ts",
|
|
22
|
+
"dev:ts": "tsup --watch",
|
|
23
|
+
"clean": "rimraf dist",
|
|
24
|
+
"test": "jest --maxWorkers=1 --passWithNoTests",
|
|
25
|
+
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
|
26
|
+
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
|
|
27
|
+
"document": "api-extractor run --local"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"/dist"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@uniformdev/tms-sdk": "19.135.1-alpha.11+9f52e6cfd6",
|
|
37
|
+
"uuid": "9.0.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/uuid": "9.0.4"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "9f52e6cfd6e562e9c759735ba2a44378388a2a82"
|
|
43
|
+
}
|