Use package.json exports field

This commit is contained in:
Samuel Elliott
2022-07-23 17:42:41 +01:00
parent d7a7d32823
commit dddb15aceb
15 changed files with 181 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ const debugFlapg = createDebug('nxapi:api:flapg');
const debugImink = createDebug('nxapi:api:imink');
const debugZncaApi = createDebug('nxapi:api:znca-api');
abstract class ZncaApi {
export abstract class ZncaApi {
constructor(
public useragent?: string
) {}
@@ -291,7 +291,7 @@ export type FResult = {
result: AndroidZncaFResponse;
});
function getZncaApiFromEnvironment(useragent?: string): ZncaApi {
export function getZncaApiFromEnvironment(useragent?: string): ZncaApi {
if (process.env.NXAPI_ZNCA_API) {
if (process.env.NXAPI_ZNCA_API === 'flapg') {
return new ZncaApiFlapg(useragent);

View File

@@ -178,9 +178,14 @@ export type PresenceUrlResponse =
CurrentUser | {user: CurrentUser} |
Friend | {friend: Friend};
export async function getPresenceFromUrl(presence_url: string) {
export async function getPresenceFromUrl(presence_url: string, useragent?: string) {
const [signal, cancel] = timeoutSignal();
const response = await fetch(presence_url, {signal}).finally(cancel);
const response = await fetch(presence_url, {
headers: {
'User-Agent': getUserAgent(useragent),
},
signal,
}).finally(cancel);
debug('fetch %s %s, response %s', 'GET', presence_url, response.status);