ronservice-nuxt
v1.0.2
Published
RonService SDK for Nuxt 3
Downloads
5
Readme
RonService Nuxt SDK
RonService Nuxt SDK, Nuxt 3 uygulamalarında RonService mikro servislerini (Auth, Activity, Storage, Sender, Pay) kolayca entegre etmenizi sağlayan bir pakettir.
Özellikler
- Auth servisi ile kullanıcı yönetimi
- Activity servisi ile etkinlik takibi
- Storage servisi ile dosya ve medya yönetimi
- Sender servisi ile e-posta gönderimi
- Pay servisi ile ödeme işlemleri
Kurulum
Paketi npm kullanarak projenize ekleyin:
npm install ronservice-nuxt
Yapılandırma
Nuxt 3 projenizde nuxt.config.ts
dosyasını aşağıdaki gibi güncelleyin:
export default defineNuxtConfig({
runtimeConfig: {
public: {
ronServiceToken: process.env.RON_SERVICE_TOKEN
}
}
})
.env
dosyanıza RonService token'ınızı ekleyin:
RON_SERVICE_TOKEN=your_token_here
Kullanım
Composable Oluşturma
Projenizde composables
klasörü altında useRonService.ts
dosyası oluşturun:
import { reactive } from 'vue'
import { useRuntimeConfig } from '#app'
import { AuthService, ActivityService, StorageService, SenderService, PayService } from 'ronservice-nuxt'
let authInstance: AuthService
let activityInstance: ActivityService
let storageInstance: StorageService
let senderInstance: SenderService
let payInstance: PayService
export function useRonService() {
const config = useRuntimeConfig()
const token = config.public.ronServiceToken
if (!authInstance) {
authInstance = new AuthService({ apiUrl: 'https://auth2.ronservice.co/api', token })
}
if (!activityInstance) {
activityInstance = new ActivityService({ apiUrl: 'https://activity.ronservice.co/api', token })
}
if (!storageInstance) {
storageInstance = new StorageService({ apiUrl: 'https://storage.ronservice.co/api', token })
}
if (!senderInstance) {
senderInstance = new SenderService({ apiUrl: 'https://sender.ronservice.co/api', token })
}
if (!payInstance) {
payInstance = new PayService({ apiUrl: 'https://api.ronpay.com/', token })
}
const ronService = reactive({
auth: authInstance,
activity: activityInstance,
storage: storageInstance,
sender: senderInstance,
pay: payInstance
})
return ronService
}
Servislerin Kullanımı
Auth Servisi
<script setup>
import { useRonService } from '~/composables/useRonService'
const { auth } = useRonService()
const login = async () => {
try {
const result = await auth.login({ username: '[email protected]', password: 'password' })
console.log(result)
} catch (error) {
console.error(error)
}
}
</script>
Activity Servisi
<script setup>
import { useRonService } from '~/composables/useRonService'
const { activity } = useRonService()
const logActivity = async () => {
try {
const result = await activity.addActivity({
status: 'SUCCESS',
type_id: 1,
content: 'User logged in',
details: { ip: '192.168.1.1' }
})
console.log(result)
} catch (error) {
console.error(error)
}
}
</script>
Storage Servisi
<script setup>
import { useRonService } from '~/composables/useRonService'
const { storage } = useRonService()
const uploadFile = async (file) => {
try {
const formData = new FormData()
formData.append('file', file)
formData.append('user_id', '1')
const result = await storage.createFile(formData)
console.log(result)
} catch (error) {
console.error(error)
}
}
</script>
Sender Servisi
<script setup>
import { useRonService } from '~/composables/useRonService'
const { sender } = useRonService()
const sendEmail = async () => {
try {
const result = await sender.sendMail({
templateId: 1,
email: '[email protected]',
params: { name: 'John Doe' }
})
console.log(result)
} catch (error) {
console.error(error)
}
}
</script>
Pay Servisi
<script setup>
import { useRonService } from '~/composables/useRonService'
const { pay } = useRonService()
const createSubscription = async () => {
try {
const result = await pay.createSubscription({
pricing_id: '1',
email: '[email protected]',
name: 'John',
surname: 'Doe',
card_holder_name: 'John Doe',
card_number: '4111111111111111',
card_expire_month: '12',
card_expire_year: '2025',
card_cvc: '123',
billing_address: '123 Main St',
billing_city: 'New York',
billing_country: 'USA',
billing_zip_code: '10001',
gsm_number: '1234567890'
})
console.log(result)
} catch (error) {
console.error(error)
}
}
</script>
API Referansı
Auth Servisi
register(credentials: RegisterCredentials): Promise<{ user: User, token: string }>
login(credentials: LoginCredentials): Promise<{ user: User, token: string }>
logout(): Promise<void>
resetPassword(data: { code: string, password: string }): Promise<{ result: boolean, message: string }>
sendVerifyEmail(data: { code: string }): Promise<{ result: boolean, message: string }>
verifyEmail(): Promise<any>
recoverPassword(data: { email: string }): Promise<{ result: boolean, message: string }>
deleteAccount(data: { password: string }): Promise<any>
getProfile(): Promise<{ result: boolean, data: { user: User } }>
updateProfile(data: UpdateProfileData): Promise<{ result: boolean, message: string, data: { user: User } }>
changePassword(data: { old_password: string, password: string }): Promise<{ result: boolean, message: string }>
getAllUsers(): Promise<{ result: boolean, data: { users: User[] } }>
getFilteredUsers(params: FilteredUsersParams): Promise<{ result: boolean, data: User[], page: any }>
getUser(userId: string): Promise<{ result: boolean, data: { user: User } }>
updateUser(userId: string, data: { subscription_id?: string, subscription_status?: string }): Promise<{ result: boolean, message: string, data: { user: User } }>
Activity Servisi
addType(title: string): Promise<{ result: boolean, message: string, data: { type: Type } }>
getTypes(perPage: number = 10): Promise<{ result: boolean, data: { types: Type[] }, page: any }>
getType(typeId: number): Promise<{ result: boolean, message: string, data: { type: Type } }>
updateType(typeId: number, title: string): Promise<{ result: boolean, message: string, data: { type: Type } }>
addActivity(data: { status: 'Success' | 'Failed', user_id: string, type_id: number, message: string, details?: object }): Promise<{ result: boolean, message: string, data: { activity: Activity } }>
getActivity(activityId: number): Promise<{ result: boolean, message: string, data: { activity: Activity } }>
getActivities(params: ActivityFilterParams): Promise<{ result: boolean, data: { activities: Activity[] }, page: any }>
Storage Servisi
createMedia(data: FormData): Promise<{ result: boolean, message: string, data: { medias: Media[] } }>
getMedias(params: StorageFilterParams): Promise<{ result: boolean, data: { medias: Media[] }, page: any }>
getMedia(mediaId: string): Promise<{ result: boolean, data: { media: Media } }>
updateMedia(mediaId: string, data: { title: string }): Promise<{ result: boolean, message: string, data: { media: Media } }>
deleteMedia(mediaId: string): Promise<{ result: boolean, message: string }>
createFile(data: FormData): Promise<{ result: boolean, message: string, data: { files: File[] } }>
getFiles(params: StorageFilterParams): Promise<{ result: boolean, data: { files: File[] }, page: any }>
getFile(fileId: string): Promise<{ result: boolean, data: { file: File } }>
updateFile(fileId: string, data: { title: string }): Promise<{ result: boolean, message: string, data: { file: File } }>
deleteFile(fileId: string): Promise<{ result: boolean, message: string }>
Sender Servisi
getMailTemplates(): Promise<{ result: boolean, message: string, data: { mail_templates: MailTemplate[] } }>
getMailTemplate(templateId: number): Promise<{ result: boolean, message: string, data: { mail_template: MailTemplate } }>
sendMail(params: SendMailParams): Promise<{ result: boolean, message: string }>
sendResetMail(params: ResetMailParams): Promise<{ result: boolean, message: string }>
sendVerifyMail(params: VerifyMailParams): Promise<{ result: boolean, message: string }>
sendUserAuthorizationMail(params: { type: string, email: string, name: string }): Promise<{ result: boolean, message: string }>
Pay Servisi
getPricingPlans(): Promise<{ result: boolean, message: string, data: { product: Product } }>
getPricingPlan(planId: string): Promise<{ result: boolean, message: string, data: { pricing_plan: PricingPlan } }>
createSubscription(params: CreateSubscriptionParams): Promise<{ result: boolean, message: string, data: { subscription: Subscription } }>
updateSubscription(subscriptionId: string, params: UpdateSubscriptionParams): Promise<{ result: boolean, message: string, data: { subscription: Subscription } }>
cancelSubscription(subscriptionId: string): Promise<{ result: boolean, message: string }>
getSubscription(subscriptionId: string): Promise<{ result: boolean, message: string, data: { subscription: Subscription } }>
getCustomers(params?: { referenceCode?: string, product_id?: string }): Promise<{ result: boolean, data: { customers: Customer[] }, page: any }>
getCustomer(customerId: string): Promise<{ result: boolean, data: { customer: Customer } }>
getAuthUserCustomer(): Promise<{ result: boolean, data: { customer: Customer } }>
getSubscriptionPaymentTransactions(subscriptionId: string): Promise<{ result: boolean, data: { transactions: any[] } }>
getExchangeRates(): Promise<any>
binCheck(bin: string): Promise<any>
getCheckoutForm(cToken: string): Promise<any>
getCustomerCards(): Promise<{ result: boolean, data: { customer_cards: any[] } }>
deleteCustomerCard(cardId: string): Promise<{ result: boolean, message: string }>
Lisans
Bu proje MIT lisansı altında lisanslanmıştır. Detaylar için LICENSE dosyasına bakın.