@cardql/react
Version:
CardQL SDK for React web applications with hooks and context providers
239 lines (232 loc) • 8.38 kB
text/typescript
import * as _cardql_core from '@cardql/core';
import { CardQLConfig, CardQL, Account, CreateAccountInput, UpdateAccountInput, App, CreateAppInput, UpdateAppInput, Customer, CreateCustomerInput, UpdateCustomerInput, Merchant, CreateMerchantInput, UpdateMerchantInput, Payment, CreatePaymentInput, UpdatePaymentInput, Ledger, CreateLedgerInput, UpdateLedgerInput } from '@cardql/core';
export * from '@cardql/core';
import * as react_jsx_runtime from 'react/jsx-runtime';
import { ReactNode } from 'react';
interface CardQLProviderProps {
config: CardQLConfig;
children: ReactNode;
}
interface CardQLContextValue {
cardql: CardQL;
config: CardQLConfig;
}
/**
* CardQL Provider component that provides CardQL instance to child components
*/
declare function CardQLProvider({ config, children }: CardQLProviderProps): react_jsx_runtime.JSX.Element;
/**
* Hook to access CardQL instance from context
*/
declare function useCardQL(): CardQLContextValue;
/**
* Hook to access CardQL client directly
*/
declare function useCardQLClient(): CardQL;
/**
* Hook to access CardQL API directly
*/
declare function useCardQLApi(): _cardql_core.CardQLApi;
interface UseQueryOptions {
enabled?: boolean;
refetchOnMount?: boolean;
refetchInterval?: number;
onSuccess?: (data: any) => void;
onError?: (error: any) => void;
}
interface UseQueryResult<T> {
data: T | undefined;
loading: boolean;
error: any;
refetch: () => Promise<void>;
refresh: () => Promise<void>;
}
/**
* Hook for executing GraphQL queries with CardQL
*/
declare function useQuery<T = any>(query: string, variables?: any, options?: UseQueryOptions): UseQueryResult<T>;
interface UseMutationOptions<TData = any, TVariables = any> {
onSuccess?: (data: TData, variables: TVariables) => void;
onError?: (error: any, variables: TVariables) => void;
onSettled?: (data: TData | undefined, error: any, variables: TVariables) => void;
}
interface UseMutationResult<TData = any, TVariables = any> {
data: TData | undefined;
loading: boolean;
error: any;
mutate: (variables: TVariables) => Promise<TData>;
mutateAsync: (variables: TVariables) => Promise<TData>;
reset: () => void;
}
/**
* Hook for executing GraphQL mutations with CardQL
*/
declare function useMutation<TData = any, TVariables = any>(mutation: string, options?: UseMutationOptions<TData, TVariables>): UseMutationResult<TData, TVariables>;
declare function useAccounts(options?: UseQueryOptions): UseQueryResult<{
accounts: Account[];
}>;
declare function useAccount(accountID: string, options?: UseQueryOptions): UseQueryResult<{
account: Account | null;
}>;
declare function useCreateAccount(options?: UseMutationOptions<{
createAccount: Account;
}, CreateAccountInput>): UseMutationResult<{
createAccount: Account;
}, CreateAccountInput>;
declare function useUpdateAccount(options?: UseMutationOptions<{
updateAccount: Account;
}, UpdateAccountInput>): UseMutationResult<{
updateAccount: Account;
}, UpdateAccountInput>;
declare function useDeleteAccount(options?: UseMutationOptions<{
deleteAccount: string;
}, {
id: string;
}>): UseMutationResult<{
deleteAccount: string;
}, {
id: string;
}>;
declare function useApps(options?: UseQueryOptions): UseQueryResult<{
apps: App[];
}>;
declare function useApp(id: string, options?: UseQueryOptions): UseQueryResult<{
app: App | null;
}>;
declare function useCreateApp(options?: UseMutationOptions<{
createApp: App;
}, CreateAppInput>): UseMutationResult<{
createApp: App;
}, CreateAppInput>;
declare function useUpdateApp(options?: UseMutationOptions<{
updateApp: App;
}, UpdateAppInput>): UseMutationResult<{
updateApp: App;
}, UpdateAppInput>;
declare function useDeleteApp(options?: UseMutationOptions<{
deleteApp: string;
}, {
id: string;
}>): UseMutationResult<{
deleteApp: string;
}, {
id: string;
}>;
declare function useCustomers(options?: UseQueryOptions): UseQueryResult<{
customers: Customer[];
}>;
declare function useCustomer(id: string, options?: UseQueryOptions): UseQueryResult<{
customer: Customer | null;
}>;
declare function useCreateCustomer(options?: UseMutationOptions<{
createCustomer: Customer;
}, CreateCustomerInput>): UseMutationResult<{
createCustomer: Customer;
}, CreateCustomerInput>;
declare function useUpdateCustomer(options?: UseMutationOptions<{
updateCustomer: Customer;
}, UpdateCustomerInput>): UseMutationResult<{
updateCustomer: Customer;
}, UpdateCustomerInput>;
declare function useDeleteCustomer(options?: UseMutationOptions<{
deleteCustomer: string;
}, {
id: string;
}>): UseMutationResult<{
deleteCustomer: string;
}, {
id: string;
}>;
declare function useMerchants(options?: UseQueryOptions): UseQueryResult<{
merchants: Merchant[];
}>;
declare function useMerchant(id: string, options?: UseQueryOptions): UseQueryResult<{
merchant: Merchant | null;
}>;
declare function useCreateMerchant(options?: UseMutationOptions<{
createMerchant: Merchant;
}, CreateMerchantInput>): UseMutationResult<{
createMerchant: Merchant;
}, CreateMerchantInput>;
declare function useUpdateMerchant(options?: UseMutationOptions<{
updateMerchant: Merchant;
}, UpdateMerchantInput>): UseMutationResult<{
updateMerchant: Merchant;
}, UpdateMerchantInput>;
declare function useDeleteMerchant(options?: UseMutationOptions<{
deleteMerchant: string;
}, {
id: string;
}>): UseMutationResult<{
deleteMerchant: string;
}, {
id: string;
}>;
declare function usePayments(options?: UseQueryOptions): UseQueryResult<{
payments: Payment[];
}>;
declare function usePayment(id: string, options?: UseQueryOptions): UseQueryResult<{
payment: Payment | null;
}>;
declare function useCreatePayment(options?: UseMutationOptions<{
createPayment: Payment;
}, CreatePaymentInput>): UseMutationResult<{
createPayment: Payment;
}, CreatePaymentInput>;
declare function useUpdatePayment(options?: UseMutationOptions<{
updatePayment: Payment;
}, UpdatePaymentInput>): UseMutationResult<{
updatePayment: Payment;
}, UpdatePaymentInput>;
declare function useDeletePayment(options?: UseMutationOptions<{
deletePayment: string;
}, {
id: string;
}>): UseMutationResult<{
deletePayment: string;
}, {
id: string;
}>;
declare function useLedgers(options?: UseQueryOptions): UseQueryResult<{
ledgers: Ledger[];
}>;
declare function useLedger(id: string, options?: UseQueryOptions): UseQueryResult<{
ledger: Ledger | null;
}>;
declare function useCreateLedger(options?: UseMutationOptions<{
createLedger: Ledger;
}, CreateLedgerInput>): UseMutationResult<{
createLedger: Ledger;
}, CreateLedgerInput>;
declare function useUpdateLedger(options?: UseMutationOptions<{
updateLedger: Ledger;
}, UpdateLedgerInput>): UseMutationResult<{
updateLedger: Ledger;
}, UpdateLedgerInput>;
declare function useDeleteLedger(options?: UseMutationOptions<{
deleteLedger: string;
}, {
id: string;
}>): UseMutationResult<{
deleteLedger: string;
}, {
id: string;
}>;
interface PaymentFormProps {
merchantID: string;
userID: string;
onSuccess?: (payment: Payment) => void;
onError?: (error: any) => void;
className?: string;
disabled?: boolean;
}
interface PaymentFormData {
amount: string;
currency: string;
description?: string;
}
/**
* Pre-built payment form component
*/
declare function PaymentForm({ merchantID, userID, onSuccess, onError, className, disabled, }: PaymentFormProps): react_jsx_runtime.JSX.Element;
export { type CardQLContextValue, CardQLProvider, type CardQLProviderProps, PaymentForm, type PaymentFormData, type PaymentFormProps, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, useAccount, useAccounts, useApp, useApps, useCardQL, useCardQLApi, useCardQLClient, useCreateAccount, useCreateApp, useCreateCustomer, useCreateLedger, useCreateMerchant, useCreatePayment, useCustomer, useCustomers, useDeleteAccount, useDeleteApp, useDeleteCustomer, useDeleteLedger, useDeleteMerchant, useDeletePayment, useLedger, useLedgers, useMerchant, useMerchants, useMutation, usePayment, usePayments, useQuery, useUpdateAccount, useUpdateApp, useUpdateCustomer, useUpdateLedger, useUpdateMerchant, useUpdatePayment };