mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-19 23:35:21 +00:00
Refactor install wizard and mail configuration
This commit is contained in:
@@ -7,6 +7,10 @@ export const API = {
|
||||
AUTH_CHECK: '/api/v1/auth/check',
|
||||
CSRF_COOKIE: '/sanctum/csrf-cookie',
|
||||
REGISTER_WITH_INVITATION: '/api/v1/auth/register-with-invitation',
|
||||
INSTALLATION_LOGIN: '/api/v1/installation/login',
|
||||
INSTALLATION_SET_DOMAIN: '/api/v1/installation/set-domain',
|
||||
INSTALLATION_WIZARD_STEP: '/api/v1/installation/wizard-step',
|
||||
INSTALLATION_SESSION_LOGIN: '/installation/session-login',
|
||||
|
||||
// Invitation Registration (public)
|
||||
INVITATION_DETAILS: '/api/v1/invitations', // append /{token}/details
|
||||
|
||||
@@ -110,11 +110,8 @@ export type {
|
||||
CreateBackupPayload,
|
||||
DeleteBackupParams,
|
||||
MailConfig,
|
||||
MailConfigResponse,
|
||||
CompanyMailConfig,
|
||||
MailDriver,
|
||||
SmtpConfig,
|
||||
MailgunConfig,
|
||||
SesConfig,
|
||||
TestMailPayload,
|
||||
PdfConfig,
|
||||
PdfConfigResponse,
|
||||
|
||||
34
resources/scripts/api/install-client.ts
Normal file
34
resources/scripts/api/install-client.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import axios, { type AxiosInstance, type InternalAxiosRequestConfig } from 'axios'
|
||||
import { LS_KEYS } from '@/scripts/config/constants'
|
||||
import * as localStore from '@/scripts/utils/local-storage'
|
||||
|
||||
export const INSTALL_WIZARD_HEADER = 'X-Install-Wizard'
|
||||
|
||||
const installClient: AxiosInstance = axios.create({
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
common: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
[INSTALL_WIZARD_HEADER]: '1',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
installClient.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
||||
const authToken = localStore.get<string>(LS_KEYS.INSTALL_AUTH_TOKEN)
|
||||
const companyId = localStore.get<string | number>(LS_KEYS.INSTALL_SELECTED_COMPANY)
|
||||
|
||||
config.headers[INSTALL_WIZARD_HEADER] = '1'
|
||||
|
||||
if (authToken) {
|
||||
config.headers.Authorization = authToken
|
||||
}
|
||||
|
||||
if (companyId !== null && companyId !== undefined && String(companyId) !== '') {
|
||||
config.headers.company = String(companyId)
|
||||
}
|
||||
|
||||
return config
|
||||
})
|
||||
|
||||
export { installClient }
|
||||
@@ -2,6 +2,7 @@ import { client } from '../client'
|
||||
import { API } from '../endpoints'
|
||||
import type { Company } from '@/scripts/types/domain/company'
|
||||
import type { ApiResponse } from '@/scripts/types/api'
|
||||
import type { CompanyMailConfig, MailConfig, TestMailPayload } from '@/scripts/types/mail-config'
|
||||
|
||||
export interface UpdateCompanyPayload {
|
||||
name: string
|
||||
@@ -78,22 +79,22 @@ export const companyService = {
|
||||
},
|
||||
|
||||
// Company Mail Configuration
|
||||
async getMailDefaultConfig(): Promise<Record<string, unknown>> {
|
||||
async getMailDefaultConfig(): Promise<Pick<MailConfig, 'from_name' | 'from_mail'>> {
|
||||
const { data } = await client.get(API.COMPANY_MAIL_DEFAULT_CONFIG)
|
||||
return data
|
||||
},
|
||||
|
||||
async getMailConfig(): Promise<Record<string, unknown>> {
|
||||
async getMailConfig(): Promise<CompanyMailConfig> {
|
||||
const { data } = await client.get(API.COMPANY_MAIL_CONFIG)
|
||||
return data
|
||||
},
|
||||
|
||||
async saveMailConfig(payload: Record<string, unknown>): Promise<{ success: boolean }> {
|
||||
async saveMailConfig(payload: Partial<CompanyMailConfig>): Promise<{ success: boolean }> {
|
||||
const { data } = await client.post(API.COMPANY_MAIL_CONFIG, payload)
|
||||
return data
|
||||
},
|
||||
|
||||
async testMailConfig(payload: Record<string, unknown>): Promise<{ success: boolean }> {
|
||||
async testMailConfig(payload: TestMailPayload): Promise<{ success: boolean }> {
|
||||
const { data } = await client.post(API.COMPANY_MAIL_TEST, payload)
|
||||
return data
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@ export type { CreateNotePayload } from './note.service'
|
||||
export type { CreateExchangeRateProviderPayload, BulkUpdatePayload, ExchangeRateResponse, ActiveProviderResponse } from './exchange-rate.service'
|
||||
export type { Module, ModuleInstallPayload, ModuleCheckResponse } from './module.service'
|
||||
export type { Backup, BackupListResponse, CreateBackupPayload, DeleteBackupParams } from './backup.service'
|
||||
export type { MailConfig, MailConfigResponse, MailDriver, SmtpConfig, MailgunConfig, SesConfig, TestMailPayload } from './mail.service'
|
||||
export type { MailConfig, CompanyMailConfig, MailDriver, TestMailPayload } from '@/scripts/types/mail-config'
|
||||
export type { PdfConfig, PdfConfigResponse, PdfDriver, DomPdfConfig, GotenbergConfig } from './pdf.service'
|
||||
export type { Disk, DiskDriversResponse, DiskDriverValue, CreateDiskPayload } from './disk.service'
|
||||
export type { CheckUpdateResponse, UpdateRelease, UpdateDownloadResponse, UpdateStepResponse, FinishUpdatePayload } from './update.service'
|
||||
|
||||
@@ -1,51 +1,6 @@
|
||||
import { client } from '../client'
|
||||
import { API } from '../endpoints'
|
||||
|
||||
export type MailDriver = string
|
||||
|
||||
export interface SmtpConfig {
|
||||
mail_driver: string
|
||||
mail_host: string
|
||||
mail_port: number | null
|
||||
mail_username: string
|
||||
mail_password: string
|
||||
mail_encryption: string
|
||||
from_mail: string
|
||||
from_name: string
|
||||
}
|
||||
|
||||
export interface MailgunConfig {
|
||||
mail_driver: string
|
||||
mail_mailgun_domain: string
|
||||
mail_mailgun_secret: string
|
||||
mail_mailgun_endpoint: string
|
||||
from_mail: string
|
||||
from_name: string
|
||||
}
|
||||
|
||||
export interface SesConfig {
|
||||
mail_driver: string
|
||||
mail_host: string
|
||||
mail_port: number | null
|
||||
mail_ses_key: string
|
||||
mail_ses_secret: string
|
||||
mail_ses_region: string
|
||||
from_mail: string
|
||||
from_name: string
|
||||
}
|
||||
|
||||
export type MailConfig = SmtpConfig | MailgunConfig | SesConfig
|
||||
|
||||
export interface MailConfigResponse {
|
||||
mail_driver: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface TestMailPayload {
|
||||
to: string
|
||||
subject: string
|
||||
message: string
|
||||
}
|
||||
import type { MailConfig, MailDriver, TestMailPayload } from '@/scripts/types/mail-config'
|
||||
|
||||
export const mailService = {
|
||||
async getDrivers(): Promise<MailDriver[]> {
|
||||
@@ -53,7 +8,7 @@ export const mailService = {
|
||||
return data
|
||||
},
|
||||
|
||||
async getConfig(): Promise<MailConfigResponse> {
|
||||
async getConfig(): Promise<MailConfig> {
|
||||
const { data } = await client.get(API.MAIL_CONFIG)
|
||||
return data
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user