amplitudeRepo.ts
3 months ago
formsRepo.ts
6 months ago
hostingRepo.ts
3 months ago
index.ts
3 months ago
pagesRepo.ts
10 months ago
reachRepo.ts
1 month ago
reachRepo.ts
63 lines
| 1 | import { useGeneralDataStore } from '@/stores/generalDataStore'; |
| 2 | import { Header } from '@/types/enums'; |
| 3 | import type { AuthorizeRequestHeaders } from '@/types/models'; |
| 4 | import type { OverviewData } from '@/types/models/reachDataModels'; |
| 5 | import { generateCorrelationId } from '@/utils/helpers'; |
| 6 | import httpService from '@/utils/services/httpService'; |
| 7 | |
| 8 | const URL = `${hostinger_reach_reach_data.rest_base_url}hostinger-reach/v1`; |
| 9 | |
| 10 | export const reachRepo = { |
| 11 | generateAuthUrl: (headers?: AuthorizeRequestHeaders) => { |
| 12 | const { nonce } = useGeneralDataStore(); |
| 13 | |
| 14 | const config = { |
| 15 | headers: { |
| 16 | [Header.CORRELATION_ID]: headers?.[Header.CORRELATION_ID] || generateCorrelationId(), |
| 17 | [Header.WP_NONCE]: nonce |
| 18 | } |
| 19 | }; |
| 20 | |
| 21 | return httpService.post<{ authUrl: string; success: boolean }>(`${URL}/generate-auth-url`, {}, config); |
| 22 | }, |
| 23 | |
| 24 | postToken: (csrfField: string, token: string) => { |
| 25 | const { nonce } = useGeneralDataStore(); |
| 26 | |
| 27 | const config = { |
| 28 | headers: { |
| 29 | [Header.CORRELATION_ID]: generateCorrelationId(), |
| 30 | [Header.WP_NONCE]: nonce |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | return httpService.post<{ success: boolean }>(`${URL}/token`, { csrfField, token }, config); |
| 35 | }, |
| 36 | |
| 37 | postConnect: () => { |
| 38 | const { nonce } = useGeneralDataStore(); |
| 39 | |
| 40 | const config = { |
| 41 | headers: { |
| 42 | [Header.CORRELATION_ID]: generateCorrelationId(), |
| 43 | [Header.WP_NONCE]: nonce |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | return httpService.post<{ success: boolean }>(`${URL}/connect`, {}, config); |
| 48 | }, |
| 49 | |
| 50 | getOverview: (headers?: AuthorizeRequestHeaders) => { |
| 51 | const { nonce } = useGeneralDataStore(); |
| 52 | |
| 53 | const config = { |
| 54 | headers: { |
| 55 | [Header.CORRELATION_ID]: headers?.[Header.CORRELATION_ID] || generateCorrelationId(), |
| 56 | [Header.WP_NONCE]: nonce |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | return httpService.get<OverviewData>(`${URL}/overview`, config); |
| 61 | } |
| 62 | }; |
| 63 |