2023-01-11 15:55:10 +00:00
|
|
|
import { AuthData } from "./apl";
|
|
|
|
import { createAPLDebug } from "./apl-debug";
|
|
|
|
import { hasAuthData } from "./has-auth-data";
|
|
|
|
|
|
|
|
const debug = createAPLDebug("authDataFromObject");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns AuthData if the object follows it's structure
|
|
|
|
*/
|
|
|
|
export const authDataFromObject = (parsed: unknown): AuthData | undefined => {
|
|
|
|
if (!hasAuthData(parsed)) {
|
|
|
|
debug("Given object did not contained AuthData");
|
|
|
|
return undefined;
|
|
|
|
}
|
2023-01-12 12:39:49 +00:00
|
|
|
const { saleorApiUrl, appId, domain, token, jwks } = parsed as AuthData;
|
2023-01-11 15:55:10 +00:00
|
|
|
return {
|
2023-01-12 12:39:49 +00:00
|
|
|
saleorApiUrl,
|
2023-01-11 15:55:10 +00:00
|
|
|
appId,
|
|
|
|
domain,
|
|
|
|
token,
|
|
|
|
jwks,
|
|
|
|
};
|
|
|
|
};
|