PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.7
Yatra – Travel Booking & Tour Operator Software v3.0.2.7
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / resources / js / api / email-automation-api.ts

email-automation-api.ts in Yatra – Travel Booking & Tour Operator Software 3.0.2.7, at resources/js/api/email-automation-api.ts

155 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Centralized REST calls for Email Automation (Yatra Pro).
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 EmailTemplateVariableMap = Record<
10 string,
11 { key: string; description?: string }[]
12 >;
13
14 export type EmailPreviewPayload = {
15 subject: string;
16 body: string;
17 };
18
19 export async function fetchEmailTemplates(): Promise<unknown[]> {
20 const raw = await apiClient.get(API_ENDPOINTS.EMAIL_TEMPLATES);
21 const unwrapped = unwrapApiPayload<unknown>(raw);
22 return Array.isArray(unwrapped) ? unwrapped : [];
23 }
24
25 export async function fetchEmailTemplate(
26 id: string | number,
27 ): Promise<Record<string, unknown> | null> {
28 return unwrapApiPayload<Record<string, unknown> | null>(
29 await apiClient.get(API_ENDPOINTS.EMAIL_TEMPLATE_GET(id)),
30 );
31 }
32
33 export async function fetchEmailTemplateVariables(): Promise<EmailTemplateVariableMap> {
34 return unwrapApiPayload<EmailTemplateVariableMap>(
35 await apiClient.get(API_ENDPOINTS.EMAIL_TEMPLATE_VARIABLES),
36 );
37 }
38
39 export async function createEmailTemplate(data: unknown): Promise<unknown> {
40 return apiClient.post(API_ENDPOINTS.EMAIL_TEMPLATES, data);
41 }
42
43 export async function updateEmailTemplate(
44 id: string | number,
45 data: unknown,
46 ): Promise<unknown> {
47 return apiClient.put(API_ENDPOINTS.EMAIL_TEMPLATE_GET(id), data);
48 }
49
50 export async function setEmailTemplateActive(
51 id: number,
52 is_active: boolean,
53 ): Promise<unknown> {
54 return apiClient.put(API_ENDPOINTS.EMAIL_TEMPLATE_GET(id), { is_active });
55 }
56
57 export async function deleteEmailTemplate(id: number): Promise<unknown> {
58 return apiClient.delete(API_ENDPOINTS.EMAIL_TEMPLATE_GET(id));
59 }
60
61 export async function duplicateEmailTemplate(id: number): Promise<unknown> {
62 return apiClient.post(API_ENDPOINTS.EMAIL_TEMPLATE_DUPLICATE(id));
63 }
64
65 export async function previewEmailTemplate(
66 id: string | number,
67 ): Promise<EmailPreviewPayload> {
68 const response = await apiClient.post(
69 API_ENDPOINTS.EMAIL_TEMPLATE_PREVIEW(id),
70 {},
71 );
72 return unwrapApiPayload<EmailPreviewPayload>(response);
73 }
74
75 export async function sendEmailTemplateTest(
76 id: string | number,
77 email: string,
78 ): Promise<unknown> {
79 return apiClient.post(API_ENDPOINTS.EMAIL_TEMPLATE_TEST(id), { email });
80 }
81
82 export async function fetchEmailSequences(): Promise<unknown[]> {
83 const raw = await apiClient.get(API_ENDPOINTS.EMAIL_SEQUENCES);
84 const unwrapped = unwrapApiPayload<unknown>(raw);
85 return Array.isArray(unwrapped) ? unwrapped : [];
86 }
87
88 export async function fetchEmailSequence(
89 id: string | number,
90 ): Promise<unknown> {
91 return unwrapApiPayload(
92 await apiClient.get(API_ENDPOINTS.EMAIL_SEQUENCE_GET(id)),
93 );
94 }
95
96 export async function createEmailSequence(data: unknown): Promise<unknown> {
97 return apiClient.post(API_ENDPOINTS.EMAIL_SEQUENCES, data);
98 }
99
100 export async function updateEmailSequence(
101 id: string | number,
102 data: unknown,
103 ): Promise<unknown> {
104 return apiClient.put(API_ENDPOINTS.EMAIL_SEQUENCE_GET(id), data);
105 }
106
107 export async function deleteEmailSequence(id: number): Promise<unknown> {
108 return apiClient.delete(API_ENDPOINTS.EMAIL_SEQUENCE_GET(id));
109 }
110
111 export async function updateEmailSequenceStatus(
112 id: number,
113 status: string,
114 ): Promise<unknown> {
115 return apiClient.put(API_ENDPOINTS.EMAIL_SEQUENCE_GET(id), { status });
116 }
117
118 export type EmailLogsPageResult = {
119 items: unknown[];
120 total: number;
121 per_page: number;
122 current_page: number;
123 };
124
125 export async function fetchEmailLogs(params?: {
126 page?: number;
127 per_page?: number;
128 template_key?: string;
129 recipient_email?: string;
130 status?: string;
131 }): Promise<EmailLogsPageResult> {
132 const raw = await apiClient.get(API_ENDPOINTS.EMAIL_LOGS, { params });
133 if (raw !== null && typeof raw === "object") {
134 const r = raw as Record<string, unknown>;
135 if (r.success === true && "data" in r) {
136 const meta = (r.meta as Record<string, unknown>) || {};
137 const items = Array.isArray(r.data) ? r.data : [];
138 return {
139 items,
140 total: Number(meta.total) || items.length,
141 per_page: Number(meta.per_page) || params?.per_page || 20,
142 current_page: Number(meta.current_page) || params?.page || 1,
143 };
144 }
145 }
146 const fallback = unwrapApiPayload<unknown>(raw);
147 const items = Array.isArray(fallback) ? fallback : [];
148 return {
149 items,
150 total: items.length,
151 per_page: params?.per_page || 20,
152 current_page: params?.page || 1,
153 };
154 }
155