mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-10 04:20:58 +00:00
160 lines
4.6 KiB
TypeScript
160 lines
4.6 KiB
TypeScript
/*
|
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
*/
|
|
|
|
import { PlexAPICore } from "../core.js";
|
|
import { encodeFormQuery } from "../lib/encodings.js";
|
|
import * as M from "../lib/matchers.js";
|
|
import { compactMap } from "../lib/primitives.js";
|
|
import { safeParse } from "../lib/schemas.js";
|
|
import { RequestOptions } from "../lib/sdks.js";
|
|
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
import { pathToFunc } from "../lib/url.js";
|
|
import {
|
|
ConnectionError,
|
|
InvalidRequestError,
|
|
RequestAbortedError,
|
|
RequestTimeoutError,
|
|
UnexpectedClientError,
|
|
} from "../sdk/models/errors/httpclienterrors.js";
|
|
import * as errors from "../sdk/models/errors/index.js";
|
|
import { SDKError } from "../sdk/models/errors/sdkerror.js";
|
|
import { SDKValidationError } from "../sdk/models/errors/sdkvalidationerror.js";
|
|
import * as operations from "../sdk/models/operations/index.js";
|
|
import { Result } from "../sdk/types/fp.js";
|
|
|
|
/**
|
|
* Get Source Connection Information
|
|
*
|
|
* @remarks
|
|
* If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
|
|
* Note: requires Plex Media Server >= 1.15.4.
|
|
*/
|
|
export async function authenticationGetSourceConnectionInformation(
|
|
client: PlexAPICore,
|
|
source: string,
|
|
options?: RequestOptions,
|
|
): Promise<
|
|
Result<
|
|
operations.GetSourceConnectionInformationResponse,
|
|
| errors.GetSourceConnectionInformationBadRequest
|
|
| errors.GetSourceConnectionInformationUnauthorized
|
|
| SDKError
|
|
| SDKValidationError
|
|
| UnexpectedClientError
|
|
| InvalidRequestError
|
|
| RequestAbortedError
|
|
| RequestTimeoutError
|
|
| ConnectionError
|
|
>
|
|
> {
|
|
const input: operations.GetSourceConnectionInformationRequest = {
|
|
source: source,
|
|
};
|
|
|
|
const parsed = safeParse(
|
|
input,
|
|
(value) =>
|
|
operations.GetSourceConnectionInformationRequest$outboundSchema.parse(
|
|
value,
|
|
),
|
|
"Input validation failed",
|
|
);
|
|
if (!parsed.ok) {
|
|
return parsed;
|
|
}
|
|
const payload = parsed.value;
|
|
const body = null;
|
|
|
|
const path = pathToFunc("/security/resources")();
|
|
|
|
const query = encodeFormQuery({
|
|
"source": payload.source,
|
|
});
|
|
|
|
const headers = new Headers(compactMap({
|
|
Accept: "application/json",
|
|
}));
|
|
|
|
const secConfig = await extractSecurity(client._options.accessToken);
|
|
const securityInput = secConfig == null ? {} : { accessToken: secConfig };
|
|
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
|
|
const context = {
|
|
operationID: "getSourceConnectionInformation",
|
|
oAuth2Scopes: [],
|
|
|
|
resolvedSecurity: requestSecurity,
|
|
|
|
securitySource: client._options.accessToken,
|
|
retryConfig: options?.retries
|
|
|| client._options.retryConfig
|
|
|| { strategy: "none" },
|
|
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
};
|
|
|
|
const requestRes = client._createRequest(context, {
|
|
security: requestSecurity,
|
|
method: "GET",
|
|
baseURL: options?.serverURL,
|
|
path: path,
|
|
headers: headers,
|
|
query: query,
|
|
body: body,
|
|
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
}, options);
|
|
if (!requestRes.ok) {
|
|
return requestRes;
|
|
}
|
|
const req = requestRes.value;
|
|
|
|
const doResult = await client._do(req, {
|
|
context,
|
|
errorCodes: ["400", "401", "4XX", "5XX"],
|
|
retryConfig: context.retryConfig,
|
|
retryCodes: context.retryCodes,
|
|
});
|
|
if (!doResult.ok) {
|
|
return doResult;
|
|
}
|
|
const response = doResult.value;
|
|
|
|
const responseFields = {
|
|
ContentType: response.headers.get("content-type")
|
|
?? "application/octet-stream",
|
|
StatusCode: response.status,
|
|
RawResponse: response,
|
|
Headers: {},
|
|
};
|
|
|
|
const [result] = await M.match<
|
|
operations.GetSourceConnectionInformationResponse,
|
|
| errors.GetSourceConnectionInformationBadRequest
|
|
| errors.GetSourceConnectionInformationUnauthorized
|
|
| SDKError
|
|
| SDKValidationError
|
|
| UnexpectedClientError
|
|
| InvalidRequestError
|
|
| RequestAbortedError
|
|
| RequestTimeoutError
|
|
| ConnectionError
|
|
>(
|
|
M.nil(200, operations.GetSourceConnectionInformationResponse$inboundSchema),
|
|
M.jsonErr(
|
|
400,
|
|
errors.GetSourceConnectionInformationBadRequest$inboundSchema,
|
|
),
|
|
M.jsonErr(
|
|
401,
|
|
errors.GetSourceConnectionInformationUnauthorized$inboundSchema,
|
|
),
|
|
M.fail("4XX"),
|
|
M.fail("5XX"),
|
|
)(response, { extraFields: responseFields });
|
|
if (!result.ok) {
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|