@kiwicom/smart-faq
Version:
39 lines (32 loc) • 694 B
JavaScript
// @flow
import ObjectHash from 'object-hash';
type Tokens = {
kwAuthToken: ?string,
loginToken: ?string,
simpleToken: ?string,
};
type requesHashType = {|
operation: { text: string, ... },
variables: {
[string]: mixed,
...,
},
|};
export const maybeGetAuthToken = (tokens: Tokens) => {
/*
Prefer login tokens over simpleToken because
simpleToken can be used only for fetching one specific booking
*/
if (tokens.kwAuthToken || tokens.loginToken) {
return null;
}
return tokens.simpleToken;
};
export const getRequestHash = ({
operation,
variables,
}: requesHashType): string =>
ObjectHash({
query: operation.text,
variables,
});