signal-desktop/ts/util/smartling.ts

42 lines
1,016 B
TypeScript
Raw Normal View History

2024-03-21 11:31:31 -07:00
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2025-09-19 13:05:51 -07:00
import { version } from './packageJson.js';
import { getUserAgent } from './getUserAgent.js';
2024-03-21 11:31:31 -07:00
type AuthenticateOptionsType = Readonly<{
userIdentifier: string;
userSecret: string;
}>;
export const API_BASE = new URL('https://api.smartling.com/');
export const PROJECT_ID = 'ef62d1ebb';
export async function authenticate({
userIdentifier,
userSecret,
}: AuthenticateOptionsType): Promise<Headers> {
const res = await fetch(new URL('./auth-api/v2/authenticate', API_BASE), {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
userIdentifier,
userSecret,
}),
});
if (!res.ok) {
throw new Error('Failed to authenticate with Smartling');
}
const {
response: { data: auth },
} = await res.json();
return new Headers({
authorization: `${auth.tokenType} ${auth.accessToken}`,
2025-09-19 13:05:51 -07:00
'user-agent': getUserAgent(version),
2024-03-21 11:31:31 -07:00
});
}