1 import type { HumanVerificationMethodType } from '../interfaces';
7 interface MergeHeaderArgs {
13 export const mergeHeaders = ({ headers: configHeaders, ...restConfig }: MergeHeaderArgs, headers: Headers) => ({
21 export const getAppVersionStr = (clientID: string, _appVersion: string) => {
22 const appVersion = process.env.NODE_ENV !== 'production' ? `${_appVersion.replace(/-.*/, '')}-dev` : _appVersion;
23 return `${clientID}@${appVersion}`;
26 export const getAppVersionHeader = (appVersion: string) => ({
27 'x-pm-appversion': appVersion,
30 export const getAppVersionHeaders = (clientID: string, appVersion: string) => {
31 return getAppVersionHeader(getAppVersionStr(clientID, appVersion));
34 export const getUIDHeaderValue = (headers: Headers) => headers?.['x-pm-uid'];
36 export const getUIDHeaders = (UID: string) => ({
40 export const getAuthHeaders = (UID: string, AccessToken: string) => ({
42 Authorization: `Bearer ${AccessToken}`,
45 export const getLocaleHeaders = (localeCode: string) => ({
46 'x-pm-locale': localeCode,
49 export const withAuthHeaders = (UID: string, AccessToken: string, config: any) =>
50 mergeHeaders(config, getAuthHeaders(UID, AccessToken));
52 export const withUIDHeaders = (UID: string, config: any) => mergeHeaders(config, getUIDHeaders(UID));
54 export const withLocaleHeaders = (localeCode: string, config: any) =>
55 mergeHeaders(config, getLocaleHeaders(localeCode));
57 export const getVerificationHeaders = (
58 token: string | undefined,
59 tokenType: HumanVerificationMethodType | undefined
61 if (!token || !tokenType) {
65 'x-pm-human-verification-token': token,
66 'x-pm-human-verification-token-type': tokenType,
70 export const getDeviceVerificationHeaders = (challengeB64: string) => {
72 'X-PM-DV': challengeB64,
76 export const getOwnershipVerificationHeaders = (value: 'lax') => {
82 export const getCroHeaders = (paymentToken: string | undefined) => {
87 'x-pm-payment-info-token': paymentToken,
91 export const withVerificationHeaders = (
92 token: string | undefined,
93 tokenType: HumanVerificationMethodType | undefined,
96 return mergeHeaders(config, getVerificationHeaders(token, tokenType));