| 1 |
/** |
| 2 |
* Centralized REST calls for plugin settings (`/settings`). |
| 3 |
*/ |
| 4 |
|
| 5 |
import { apiClient } from "../lib/api-client"; |
| 6 |
import { API_ENDPOINTS } from "../lib/api-endpoints"; |
| 7 |
import { unwrapApiPayload } from "../lib/unwrap-api-payload"; |
| 8 |
|
| 9 |
export type CoreEmailTemplatePreviewPayload = { |
| 10 |
template_key: string; |
| 11 |
subject: string; |
| 12 |
body: string; |
| 13 |
/** Optional Yatra trip ID — merges real trip_name, trip_url, trip_id into preview samples. */ |
| 14 |
trip_id?: number; |
| 15 |
}; |
| 16 |
|
| 17 |
export type EmailPreviewResult = { |
| 18 |
subject: string; |
| 19 |
body: string; |
| 20 |
}; |
| 21 |
|
| 22 |
export async function fetchSettings(): Promise<Record<string, unknown>> { |
| 23 |
return unwrapApiPayload<Record<string, unknown>>( |
| 24 |
await apiClient.get(API_ENDPOINTS.SETTINGS), |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
export async function saveSettings( |
| 29 |
data: Record<string, unknown>, |
| 30 |
): Promise<unknown> { |
| 31 |
return apiClient.put(API_ENDPOINTS.SETTINGS, data); |
| 32 |
} |
| 33 |
|
| 34 |
export async function previewCoreEmailTemplate( |
| 35 |
payload: CoreEmailTemplatePreviewPayload, |
| 36 |
): Promise<EmailPreviewResult> { |
| 37 |
const response = await apiClient.post( |
| 38 |
API_ENDPOINTS.SETTINGS_EMAIL_TEMPLATE_PREVIEW, |
| 39 |
payload, |
| 40 |
); |
| 41 |
return unwrapApiPayload<EmailPreviewResult>(response); |
| 42 |
} |
| 43 |
|
| 44 |
export async function fetchWordPressPages(): Promise<unknown> { |
| 45 |
return apiClient.get(API_ENDPOINTS.SETTINGS_PAGES); |
| 46 |
} |
| 47 |
|
| 48 |
export async function postFlushRewriteRules(): Promise<unknown> { |
| 49 |
return apiClient.post(API_ENDPOINTS.SETTINGS_FLUSH_REWRITE_RULES); |
| 50 |
} |
| 51 |
|
| 52 |
export async function fetchBookingPageShortcodeStatus( |
| 53 |
pageId: number, |
| 54 |
): Promise<unknown> { |
| 55 |
return apiClient.get(API_ENDPOINTS.SETTINGS_CHECK_SHORTCODE(pageId)); |
| 56 |
} |
| 57 |
|
| 58 |
export async function postInsertBookingShortcode( |
| 59 |
pageId: number, |
| 60 |
): Promise<unknown> { |
| 61 |
return apiClient.post(API_ENDPOINTS.SETTINGS_INSERT_SHORTCODE(pageId)); |
| 62 |
} |
| 63 |
|
| 64 |
export async function fetchPaymentGatewayDefinitions(): Promise<unknown> { |
| 65 |
return apiClient.get(API_ENDPOINTS.PAYMENT_GATEWAY_DEFINITIONS); |
| 66 |
} |
| 67 |
|