PluginProbe
SureMail – SMTP and Email Logs Plugin with Amazon SES, Postmark, and Other Providers / 2.0.0
SureMail – SMTP and Email Logs Plugin with Amazon SES, Postmark, and Other Providers v2.0.0
2.0.2 2.0.1 2.0.0 1.9.5 trunk 0.0.4 0.0.5 0.0.6 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 All 31 releases
suremails / src / api / settings.js

settings.js in SureMail – SMTP and Email Logs Plugin with Amazon SES, Postmark, and Other Providers 2.0.0, at src/api/settings.js

109 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2 import { __ } from '@wordpress/i18n';
3 // Fetch settings from the API
4 export const fetchSettings = async () => {
5 try {
6 const response = await apiFetch( {
7 path: '/suremails/v1/get-settings',
8 method: 'POST',
9 headers: {
10 'Content-Type': 'application/json',
11 'X-WP-Nonce': suremails.nonce,
12 },
13 } );
14
15 if ( typeof response !== 'object' ) {
16 throw new Error( 'Invalid JSON response' );
17 }
18 return response;
19 } catch ( error ) {
20 throw new Error( error.message || 'Error fetching settings' );
21 }
22 };
23
24 // Save settings to the API
25 export const saveSettings = async ( updatedSettings ) => {
26 try {
27 const response = await apiFetch( {
28 path: '/suremails/v1/set-settings',
29 method: 'POST',
30 headers: {
31 'X-WP-Nonce': suremails.nonce,
32 'Content-Type': 'application/json',
33 },
34 body: JSON.stringify( {
35 settings: {
36 delete_email_logs_after:
37 updatedSettings.settings.delete_email_logs_after,
38 log_emails: updatedSettings.settings.log_emails,
39 email_simulation: updatedSettings.settings.email_simulation,
40 default_connection:
41 updatedSettings.settings.default_connection,
42 emailSummaryActive:
43 updatedSettings.settings.emailSummaryActive,
44 emailSummaryDay: updatedSettings.settings.emailSummaryDay,
45 showInSidebar: updatedSettings.settings.showInSidebar,
46 analytics: updatedSettings.settings.analytics,
47 },
48 } ),
49 } );
50 return response;
51 } catch ( error ) {
52 throw new Error( error.message || 'Error saving settings' );
53 }
54 };
55
56 /**
57 * Set the Reputation Shield (Content Guard) activation status.
58 *
59 * When a boolean `status` is passed, the backend is instructed to set the
60 * option to that exact value. If omitted, the endpoint preserves its legacy
61 * toggle behavior for backward compatibility.
62 *
63 * @param {boolean} [status] Desired activation state.
64 * @return {Object} The response
65 */
66 export const activateContentGuard = async ( status ) => {
67 try {
68 const hasStatus = typeof status === 'boolean';
69 return await apiFetch( {
70 path: '/suremails/v1/content-guard/activate',
71 method: hasStatus ? 'POST' : 'GET',
72 headers: {
73 'Content-Type': 'application/json',
74 'X-WP-Nonce': suremails.nonce,
75 },
76 ...( hasStatus && {
77 data: { status: status ? 'yes' : 'no' },
78 } ),
79 } );
80 } catch ( error ) {
81 throw new Error(
82 error?.data?.message ||
83 __( 'Error activating Reputation Shield', 'suremails' )
84 );
85 }
86 };
87
88 /**
89 * Save user details for Content Guard
90 *
91 * @param {Object} userDetails - The user details
92 * @return {Object} The response
93 */
94 export const saveUserDetails = async ( userDetails ) => {
95 try {
96 return await apiFetch( {
97 path: '/suremails/v1/content-guard/user-details',
98 method: 'POST',
99 headers: {
100 'X-WP-Nonce': suremails.nonce,
101 'Content-Type': 'application/json',
102 },
103 body: JSON.stringify( userDetails ),
104 } );
105 } catch ( error ) {
106 throw new Error( error.data.message || 'Error saving user details' );
107 }
108 };
109