mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-04-19 18:54:08 +00:00
feat(sdk): more sdk ts fetch utils
This commit is contained in:
21
shared/sdk-ts/src/attachments.ts
Normal file
21
shared/sdk-ts/src/attachments.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { ApiFetcher } from './fetch-utils';
|
||||
import type { paths } from './schema';
|
||||
|
||||
export const ATTACHMENTS_ROUTES = {
|
||||
BY_ID: '/api/attachments/{id}',
|
||||
PRESIGNED_URL: '/api/attachments/{id}/presigned-url',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
export async function deleteAttachment(fetcher: ApiFetcher, id: string): Promise<void> {
|
||||
const del = fetcher.path(ATTACHMENTS_ROUTES.BY_ID).method('delete').create();
|
||||
await del({ id });
|
||||
}
|
||||
|
||||
export async function fetchAttachmentPresignedUrl(
|
||||
fetcher: ApiFetcher,
|
||||
id: string
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(ATTACHMENTS_ROUTES.PRESIGNED_URL).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
232
shared/sdk-ts/src/bank-rules.ts
Normal file
232
shared/sdk-ts/src/bank-rules.ts
Normal file
@@ -0,0 +1,232 @@
|
||||
import type { ApiFetcher } from './fetch-utils';
|
||||
import type { paths } from './schema';
|
||||
|
||||
export const BANK_RULES_ROUTES = {
|
||||
RULES: '/api/banking/rules',
|
||||
RULE_BY_ID: '/api/banking/rules/{id}',
|
||||
ACCOUNTS_DISCONNECT: '/api/banking/accounts/{id}/disconnect',
|
||||
ACCOUNTS_REFRESH: '/api/banking/accounts/{id}/refresh',
|
||||
MATCHING_MATCHED: '/api/banking/matching/matched',
|
||||
MATCHING_MATCH: '/api/banking/matching/match',
|
||||
MATCHING_UNMATCH: '/api/banking/matching/unmatch/{uncategorizedTransactionId}',
|
||||
EXCLUDE: '/api/banking/exclude/{id}',
|
||||
EXCLUDE_BULK: '/api/banking/exclude/bulk',
|
||||
EXCLUDED_LIST: '/api/banking/exclude',
|
||||
RECOGNIZED: '/api/banking/recognized/{recognizedTransactionId}',
|
||||
RECOGNIZED_LIST: '/api/banking/recognized',
|
||||
PENDING: '/api/banking/pending',
|
||||
UNCATEGORIZED_AUTOFILL: '/api/banking/uncategorized/autofill',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
type GetBankRules = paths[typeof BANK_RULES_ROUTES.RULES]['get'];
|
||||
type GetBankRule = paths[typeof BANK_RULES_ROUTES.RULE_BY_ID]['get'];
|
||||
type CreateBankRule = paths[typeof BANK_RULES_ROUTES.RULES]['post'];
|
||||
type EditBankRule = paths[typeof BANK_RULES_ROUTES.RULE_BY_ID]['put'];
|
||||
type DeleteBankRule = paths[typeof BANK_RULES_ROUTES.RULE_BY_ID]['delete'];
|
||||
|
||||
type GetBankRules200 = GetBankRules['responses'][200];
|
||||
type GetBankRule200 = GetBankRule['responses'][200];
|
||||
type CreateBankRule201 = CreateBankRule['responses'][201];
|
||||
|
||||
export type BankRulesListResponse = GetBankRules200 extends {
|
||||
content?: { 'application/json': infer J };
|
||||
}
|
||||
? J
|
||||
: unknown;
|
||||
export type BankRuleResponse = GetBankRule200 extends {
|
||||
content?: { 'application/json': infer J };
|
||||
}
|
||||
? J
|
||||
: unknown;
|
||||
export type CreateBankRuleBody = CreateBankRule['requestBody']['content']['application/json'];
|
||||
export type EditBankRuleBody = EditBankRule['requestBody']['content']['application/json'];
|
||||
export type CreateBankRuleResponse = CreateBankRule201 extends {
|
||||
content?: { 'application/json': infer J };
|
||||
}
|
||||
? J
|
||||
: unknown;
|
||||
|
||||
export async function fetchBankRules(fetcher: ApiFetcher): Promise<BankRulesListResponse> {
|
||||
const get = fetcher.path(BANK_RULES_ROUTES.RULES).method('get').create();
|
||||
const { data } = await get({});
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchBankRule(
|
||||
fetcher: ApiFetcher,
|
||||
id: number
|
||||
): Promise<BankRuleResponse> {
|
||||
const get = fetcher.path(BANK_RULES_ROUTES.RULE_BY_ID).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createBankRule(
|
||||
fetcher: ApiFetcher,
|
||||
body: CreateBankRuleBody
|
||||
): Promise<CreateBankRuleResponse> {
|
||||
const post = fetcher.path(BANK_RULES_ROUTES.RULES).method('post').create();
|
||||
const { data } = await post(body);
|
||||
return data as CreateBankRuleResponse;
|
||||
}
|
||||
|
||||
export async function editBankRule(
|
||||
fetcher: ApiFetcher,
|
||||
id: number,
|
||||
body: EditBankRuleBody
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(BANK_RULES_ROUTES.RULE_BY_ID).method('put').create();
|
||||
await put({ id, ...body });
|
||||
}
|
||||
|
||||
export async function deleteBankRule(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const del = fetcher.path(BANK_RULES_ROUTES.RULE_BY_ID).method('delete').create();
|
||||
await del({ id });
|
||||
}
|
||||
|
||||
export async function disconnectBankAccount(
|
||||
fetcher: ApiFetcher,
|
||||
id: number
|
||||
): Promise<void> {
|
||||
const post = fetcher
|
||||
.path(BANK_RULES_ROUTES.ACCOUNTS_DISCONNECT)
|
||||
.method('post')
|
||||
.create();
|
||||
await post({ id });
|
||||
}
|
||||
|
||||
export async function refreshBankAccount(
|
||||
fetcher: ApiFetcher,
|
||||
id: number
|
||||
): Promise<void> {
|
||||
const post = fetcher
|
||||
.path(BANK_RULES_ROUTES.ACCOUNTS_REFRESH)
|
||||
.method('post')
|
||||
.create();
|
||||
await post({ id });
|
||||
}
|
||||
|
||||
export async function fetchMatchedTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
uncategorizedTransactionIds: number[]
|
||||
): Promise<unknown> {
|
||||
const get = fetcher
|
||||
.path(BANK_RULES_ROUTES.MATCHING_MATCHED)
|
||||
.method('get')
|
||||
.create();
|
||||
const ids = uncategorizedTransactionIds.map(String);
|
||||
const { data } = await get({ uncategorizedTransactionIds: ids });
|
||||
return data;
|
||||
}
|
||||
|
||||
export type MatchTransactionBody = {
|
||||
uncategorizedTransactions: number[];
|
||||
matchedTransactions: Array<{ reference_type: string; reference_id: number }>;
|
||||
};
|
||||
|
||||
export async function matchTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
body: MatchTransactionBody
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(BANK_RULES_ROUTES.MATCHING_MATCH).method('post').create();
|
||||
await (post as (body: unknown) => Promise<unknown>)(body);
|
||||
}
|
||||
|
||||
export async function unmatchMatchedTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
uncategorizedTransactionId: number
|
||||
): Promise<void> {
|
||||
const patch = fetcher
|
||||
.path(BANK_RULES_ROUTES.MATCHING_UNMATCH)
|
||||
.method('patch')
|
||||
.create();
|
||||
await patch({ uncategorizedTransactionId });
|
||||
}
|
||||
|
||||
export async function excludeBankTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
id: number | string
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(BANK_RULES_ROUTES.EXCLUDE).method('put').create();
|
||||
await put({ id: String(id) });
|
||||
}
|
||||
|
||||
export async function unexcludeBankTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
id: number | string
|
||||
): Promise<void> {
|
||||
const del = fetcher.path(BANK_RULES_ROUTES.EXCLUDE).method('delete').create();
|
||||
await del({ id: String(id) });
|
||||
}
|
||||
|
||||
export async function excludeBankTransactionsBulk(
|
||||
fetcher: ApiFetcher,
|
||||
ids: Array<number | string>
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(BANK_RULES_ROUTES.EXCLUDE_BULK).method('put').create();
|
||||
await (put as (body?: { ids?: unknown[] }) => Promise<unknown>)({ ids });
|
||||
}
|
||||
|
||||
export async function unexcludeBankTransactionsBulk(
|
||||
fetcher: ApiFetcher,
|
||||
ids: Array<number | string>
|
||||
): Promise<void> {
|
||||
const del = fetcher.path(BANK_RULES_ROUTES.EXCLUDE_BULK).method('delete').create();
|
||||
await (del as (body?: { ids?: unknown[] }) => Promise<unknown>)({ ids });
|
||||
}
|
||||
|
||||
export async function fetchRecognizedTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
recognizedTransactionId: number
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(BANK_RULES_ROUTES.RECOGNIZED).method('get').create();
|
||||
const { data } = await get({ recognizedTransactionId });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchRecognizedTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
params?: Record<string, unknown>
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(BANK_RULES_ROUTES.RECOGNIZED_LIST).method('get').create();
|
||||
const { data } = await (get as (q?: Record<string, unknown>) => Promise<{ data: unknown }>)(
|
||||
params ?? {}
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchExcludedBankTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
params?: Record<string, unknown>
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(BANK_RULES_ROUTES.EXCLUDED_LIST).method('get').create();
|
||||
const { data } = await (get as (q?: Record<string, unknown>) => Promise<{ data: unknown }>)(
|
||||
params ?? {}
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchPendingTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
params?: Record<string, unknown>
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(BANK_RULES_ROUTES.PENDING).method('get').create();
|
||||
const { data } = await (get as (q?: Record<string, unknown>) => Promise<{ data: unknown }>)(
|
||||
params ?? {}
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchAutofillCategorizeTransaction(
|
||||
fetcher: ApiFetcher,
|
||||
uncategorizedTransactionIds: number[]
|
||||
): Promise<unknown> {
|
||||
const get = fetcher
|
||||
.path(BANK_RULES_ROUTES.UNCATEGORIZED_AUTOFILL)
|
||||
.method('get')
|
||||
.create();
|
||||
const { data } = await (get as (q: unknown) => Promise<{ data: unknown }>)({
|
||||
uncategorizedTransactionIds,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -20,7 +20,8 @@ export async function fetchBankingAccounts(fetcher: ApiFetcher): Promise<Banking
|
||||
export async function fetchBankingAccountSummary(
|
||||
fetcher: ApiFetcher,
|
||||
bankAccountId: number
|
||||
): Promise<void> {
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(BANKING_ACCOUNTS_ROUTES.SUMMARY).method('get').create();
|
||||
await get({ bankAccountId });
|
||||
const { data } = await get({ bankAccountId });
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,16 @@ export const CURRENCIES_ROUTES = {
|
||||
|
||||
type GetCurrencies = paths[typeof CURRENCIES_ROUTES.LIST]['get'];
|
||||
type GetCurrencyByCode = paths[typeof CURRENCIES_ROUTES.BY_CURRENCY_CODE]['get'];
|
||||
type CreateCurrency = paths[typeof CURRENCIES_ROUTES.LIST]['post'];
|
||||
type EditCurrency = paths[typeof CURRENCIES_ROUTES.BY_ID]['put'];
|
||||
type DeleteCurrency = paths[typeof CURRENCIES_ROUTES.BY_CODE]['delete'];
|
||||
|
||||
type GetCurrencies200 = GetCurrencies['responses'][200];
|
||||
type GetCurrencyByCode200 = GetCurrencyByCode['responses'][200];
|
||||
export type CurrenciesListResponse = GetCurrencies200 extends { content?: { 'application/json': infer J } } ? J : unknown;
|
||||
export type Currency = GetCurrencyByCode200 extends { content?: { 'application/json': infer J } } ? J : unknown;
|
||||
export type CreateCurrencyBody = CreateCurrency extends { requestBody: { content: { 'application/json': infer J } } } ? J : Record<string, unknown>;
|
||||
export type EditCurrencyBody = EditCurrency extends { requestBody: { content: { 'application/json': infer J } } } ? J : Record<string, unknown>;
|
||||
|
||||
export async function fetchCurrencies(fetcher: ApiFetcher): Promise<CurrenciesListResponse> {
|
||||
const get = fetcher.path(CURRENCIES_ROUTES.LIST).method('get').create();
|
||||
@@ -32,3 +37,25 @@ export async function fetchCurrencyByCode(fetcher: ApiFetcher, currencyCode: str
|
||||
export async function fetchCurrency(fetcher: ApiFetcher, id: number): Promise<Currency> {
|
||||
return fetchCurrencyByCode(fetcher, String(id));
|
||||
}
|
||||
|
||||
export async function createCurrency(
|
||||
fetcher: ApiFetcher,
|
||||
values: CreateCurrencyBody
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(CURRENCIES_ROUTES.LIST).method('post').create();
|
||||
await post(values as never);
|
||||
}
|
||||
|
||||
export async function editCurrency(
|
||||
fetcher: ApiFetcher,
|
||||
id: number,
|
||||
values: EditCurrencyBody
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(CURRENCIES_ROUTES.BY_ID).method('put').create();
|
||||
await put({ id, ...values } as never);
|
||||
}
|
||||
|
||||
export async function deleteCurrency(fetcher: ApiFetcher, code: string): Promise<void> {
|
||||
const del = fetcher.path(CURRENCIES_ROUTES.BY_CODE).method('delete').create();
|
||||
await del({ code });
|
||||
}
|
||||
|
||||
@@ -3,6 +3,24 @@ import type { paths } from './schema';
|
||||
|
||||
export type ApiFetcher = ReturnType<typeof Fetcher.for<paths>>;
|
||||
|
||||
export interface CreateApiFetcherConfig {
|
||||
baseUrl?: string;
|
||||
init?: RequestInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and configures an ApiFetcher for use with sdk-ts fetch functions.
|
||||
* Call this with baseUrl (e.g. '/api') and init.headers (Authorization, organization-id, etc.) from the app.
|
||||
*/
|
||||
export function createApiFetcher(config?: CreateApiFetcherConfig): ApiFetcher {
|
||||
const fetcher = Fetcher.for<paths>();
|
||||
fetcher.configure({
|
||||
baseUrl: config?.baseUrl ?? '',
|
||||
init: config?.init,
|
||||
});
|
||||
return fetcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips leading slash from a path segment to avoid double slashes when joining with a base (e.g. `/api/` + path).
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Run `pnpm run generate:sdk-types` from repo root to regenerate schema from the server OpenAPI spec.
|
||||
*/
|
||||
export type { paths, components, operations } from './schema';
|
||||
export { normalizeApiPath, ApiFetcher } from './fetch-utils';
|
||||
export type { ApiFetcher, CreateApiFetcherConfig } from './fetch-utils';
|
||||
export { normalizeApiPath, createApiFetcher } from './fetch-utils';
|
||||
export {
|
||||
ACCOUNTS_ROUTES,
|
||||
fetchAccounts,
|
||||
@@ -272,14 +273,45 @@ export {
|
||||
fetchCurrencies,
|
||||
fetchCurrency,
|
||||
fetchCurrencyByCode,
|
||||
createCurrency,
|
||||
editCurrency,
|
||||
deleteCurrency,
|
||||
} from './currencies';
|
||||
export type { CurrenciesListResponse, Currency } from './currencies';
|
||||
export type {
|
||||
CurrenciesListResponse,
|
||||
Currency,
|
||||
CreateCurrencyBody,
|
||||
EditCurrencyBody,
|
||||
} from './currencies';
|
||||
export {
|
||||
TAX_RATES_ROUTES,
|
||||
fetchTaxRates,
|
||||
fetchTaxRate,
|
||||
createTaxRate,
|
||||
editTaxRate,
|
||||
deleteTaxRate,
|
||||
activateTaxRate,
|
||||
inactivateTaxRate,
|
||||
} from './tax-rates';
|
||||
export type {
|
||||
TaxRatesListResponse,
|
||||
TaxRate,
|
||||
CreateTaxRateBody,
|
||||
EditTaxRateBody,
|
||||
} from './tax-rates';
|
||||
export {
|
||||
ATTACHMENTS_ROUTES,
|
||||
deleteAttachment,
|
||||
fetchAttachmentPresignedUrl,
|
||||
} from './attachments';
|
||||
export {
|
||||
INVITE_ROUTES,
|
||||
inviteUser,
|
||||
resendInvite,
|
||||
acceptInvite,
|
||||
fetchInviteCheck,
|
||||
} from './invite';
|
||||
export type { InviteUserBody } from './invite';
|
||||
export type { InviteUserBody, AcceptInviteBody } from './invite';
|
||||
export {
|
||||
AUTH_ROUTES,
|
||||
fetchAuthedAccount,
|
||||
@@ -315,7 +347,12 @@ export {
|
||||
TRANSACTIONS_LOCKING_ROUTES,
|
||||
fetchTransactionsLocking,
|
||||
fetchTransactionsLockingByModule,
|
||||
lockTransactions,
|
||||
cancelLockTransactions,
|
||||
unlockPartialTransactions,
|
||||
cancelUnlockPartialTransactions,
|
||||
} from './transactions-locking';
|
||||
export type { TransactionsLockingListResponse } from './transactions-locking';
|
||||
export {
|
||||
VENDOR_CREDITS_ROUTES,
|
||||
fetchVendorCredits,
|
||||
@@ -338,12 +375,24 @@ export {
|
||||
createSaleEstimate,
|
||||
editSaleEstimate,
|
||||
deleteSaleEstimate,
|
||||
bulkDeleteSaleEstimates,
|
||||
validateBulkDeleteSaleEstimates,
|
||||
deliverSaleEstimate,
|
||||
approveSaleEstimate,
|
||||
rejectSaleEstimate,
|
||||
notifySaleEstimateBySms,
|
||||
fetchSaleEstimateSmsDetails,
|
||||
fetchSaleEstimateMail,
|
||||
sendSaleEstimateMail,
|
||||
fetchSaleEstimatesState,
|
||||
} from './sale-estimates';
|
||||
export type {
|
||||
SaleEstimatesListResponse,
|
||||
SaleEstimate,
|
||||
CreateSaleEstimateBody,
|
||||
EditSaleEstimateBody,
|
||||
BulkDeleteEstimatesBody,
|
||||
ValidateBulkDeleteEstimatesResponse,
|
||||
} from './sale-estimates';
|
||||
export {
|
||||
SALE_RECEIPTS_ROUTES,
|
||||
@@ -366,12 +415,20 @@ export {
|
||||
createPaymentReceived,
|
||||
editPaymentReceived,
|
||||
deletePaymentReceived,
|
||||
bulkDeletePaymentsReceived,
|
||||
validateBulkDeletePaymentsReceived,
|
||||
fetchPaymentReceiveEditPage,
|
||||
fetchPaymentReceiveMail,
|
||||
sendPaymentReceiveMail,
|
||||
fetchPaymentReceivedState,
|
||||
} from './payment-receives';
|
||||
export type {
|
||||
PaymentsReceivedListResponse,
|
||||
PaymentReceived,
|
||||
CreatePaymentReceivedBody,
|
||||
EditPaymentReceivedBody,
|
||||
BulkDeletePaymentsReceivedBody,
|
||||
ValidateBulkDeletePaymentsReceivedResponse,
|
||||
} from './payment-receives';
|
||||
export {
|
||||
BILL_PAYMENTS_ROUTES,
|
||||
@@ -380,6 +437,7 @@ export {
|
||||
createBillPayment,
|
||||
editBillPayment,
|
||||
deleteBillPayment,
|
||||
fetchBillPaymentEditPage,
|
||||
} from './payment-mades';
|
||||
export type {
|
||||
BillPaymentsListResponse,
|
||||
@@ -432,3 +490,33 @@ export {
|
||||
fetchBankingAccountSummary,
|
||||
} from './cashflow-accounts';
|
||||
export type { BankingAccountsListResponse } from './cashflow-accounts';
|
||||
export {
|
||||
BANK_RULES_ROUTES,
|
||||
fetchBankRules,
|
||||
fetchBankRule,
|
||||
createBankRule,
|
||||
editBankRule,
|
||||
deleteBankRule,
|
||||
disconnectBankAccount,
|
||||
refreshBankAccount,
|
||||
fetchMatchedTransactions,
|
||||
matchTransaction,
|
||||
unmatchMatchedTransaction,
|
||||
excludeBankTransaction,
|
||||
unexcludeBankTransaction,
|
||||
excludeBankTransactionsBulk,
|
||||
unexcludeBankTransactionsBulk,
|
||||
fetchRecognizedTransaction,
|
||||
fetchRecognizedTransactions,
|
||||
fetchExcludedBankTransactions,
|
||||
fetchPendingTransactions,
|
||||
fetchAutofillCategorizeTransaction,
|
||||
} from './bank-rules';
|
||||
export type {
|
||||
BankRulesListResponse,
|
||||
BankRuleResponse,
|
||||
CreateBankRuleBody,
|
||||
EditBankRuleBody,
|
||||
CreateBankRuleResponse,
|
||||
MatchTransactionBody,
|
||||
} from './bank-rules';
|
||||
|
||||
@@ -10,8 +10,27 @@ export const INVITE_ROUTES = {
|
||||
|
||||
type InviteUser = paths[typeof INVITE_ROUTES.INVITE]['patch'];
|
||||
type ResendInvite = paths[typeof INVITE_ROUTES.RESEND]['post'];
|
||||
type AcceptInvite = paths[typeof INVITE_ROUTES.ACCEPT]['post'];
|
||||
type CheckInvite = paths[typeof INVITE_ROUTES.CHECK]['get'];
|
||||
|
||||
export type InviteUserBody = InviteUser['requestBody']['content']['application/json'];
|
||||
export type AcceptInviteBody = AcceptInvite extends { requestBody: { content: { 'application/json': infer J } } } ? J : Record<string, unknown>;
|
||||
|
||||
export async function acceptInvite(
|
||||
fetcher: ApiFetcher,
|
||||
token: string,
|
||||
values: AcceptInviteBody
|
||||
): Promise<unknown> {
|
||||
const post = fetcher.path(INVITE_ROUTES.ACCEPT).method('post').create();
|
||||
const { data } = await post({ token, ...values } as never);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchInviteCheck(fetcher: ApiFetcher, token: string): Promise<unknown> {
|
||||
const get = fetcher.path(INVITE_ROUTES.CHECK).method('get').create();
|
||||
const { data } = await get({ token });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function inviteUser(
|
||||
fetcher: ApiFetcher,
|
||||
|
||||
@@ -55,3 +55,12 @@ export async function deleteBillPayment(fetcher: ApiFetcher, billPaymentId: numb
|
||||
const del = fetcher.path(BILL_PAYMENTS_ROUTES.BY_ID).method('delete').create();
|
||||
await del({ billPaymentId });
|
||||
}
|
||||
|
||||
export async function fetchBillPaymentEditPage(
|
||||
fetcher: ApiFetcher,
|
||||
billPaymentId: number
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(BILL_PAYMENTS_ROUTES.EDIT_PAGE).method('get').create();
|
||||
const { data } = await get({ billPaymentId });
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ export const PAYMENTS_RECEIVED_ROUTES = {
|
||||
STATE: '/api/payments-received/state',
|
||||
VALIDATE_BULK_DELETE: '/api/payments-received/validate-bulk-delete',
|
||||
BULK_DELETE: '/api/payments-received/bulk-delete',
|
||||
EDIT_PAGE: '/api/payments-received/{id}/edit-page',
|
||||
MAIL: '/api/payments-received/{id}/mail',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
type GetPaymentsReceived = paths[typeof PAYMENTS_RECEIVED_ROUTES.LIST]['get'];
|
||||
@@ -55,3 +57,62 @@ export async function deletePaymentReceived(fetcher: ApiFetcher, id: number): Pr
|
||||
const del = fetcher.path(PAYMENTS_RECEIVED_ROUTES.BY_ID).method('delete').create();
|
||||
await del({ id });
|
||||
}
|
||||
|
||||
export type BulkDeletePaymentsReceivedBody = { ids: number[]; skipUndeletable?: boolean };
|
||||
export type ValidateBulkDeletePaymentsReceivedResponse = {
|
||||
deletableCount: number;
|
||||
nonDeletableCount: number;
|
||||
deletableIds: number[];
|
||||
nonDeletableIds: number[];
|
||||
};
|
||||
|
||||
export async function bulkDeletePaymentsReceived(
|
||||
fetcher: ApiFetcher,
|
||||
body: BulkDeletePaymentsReceivedBody
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(PAYMENTS_RECEIVED_ROUTES.BULK_DELETE).method('post').create();
|
||||
await post({ ids: body.ids, skipUndeletable: body.skipUndeletable ?? false } as never);
|
||||
}
|
||||
|
||||
export async function validateBulkDeletePaymentsReceived(
|
||||
fetcher: ApiFetcher,
|
||||
ids: number[]
|
||||
): Promise<ValidateBulkDeletePaymentsReceivedResponse> {
|
||||
const post = fetcher.path(PAYMENTS_RECEIVED_ROUTES.VALIDATE_BULK_DELETE).method('post').create();
|
||||
const { data } = await post({ ids, skipUndeletable: false } as never);
|
||||
return data as ValidateBulkDeletePaymentsReceivedResponse;
|
||||
}
|
||||
|
||||
export async function fetchPaymentReceiveEditPage(
|
||||
fetcher: ApiFetcher,
|
||||
id: number
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(PAYMENTS_RECEIVED_ROUTES.EDIT_PAGE).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchPaymentReceiveMail(
|
||||
fetcher: ApiFetcher,
|
||||
id: number
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(PAYMENTS_RECEIVED_ROUTES.MAIL).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function sendPaymentReceiveMail(
|
||||
fetcher: ApiFetcher,
|
||||
id: number,
|
||||
body: Record<string, unknown>
|
||||
): Promise<unknown> {
|
||||
const post = fetcher.path(PAYMENTS_RECEIVED_ROUTES.MAIL).method('post').create();
|
||||
const { data } = await post({ id, ...body } as never);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchPaymentReceivedState(fetcher: ApiFetcher): Promise<unknown> {
|
||||
const get = fetcher.path(PAYMENTS_RECEIVED_ROUTES.STATE).method('get').create();
|
||||
const { data } = await get({});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@ export const SALE_ESTIMATES_ROUTES = {
|
||||
STATE: '/api/sale-estimates/state',
|
||||
VALIDATE_BULK_DELETE: '/api/sale-estimates/validate-bulk-delete',
|
||||
BULK_DELETE: '/api/sale-estimates/bulk-delete',
|
||||
DELIVER: '/api/sale-estimates/{id}/deliver',
|
||||
APPROVE: '/api/sale-estimates/{id}/approve',
|
||||
REJECT: '/api/sale-estimates/{id}/reject',
|
||||
NOTIFY_SMS: '/api/sale-estimates/{id}/notify-sms',
|
||||
SMS_DETAILS: '/api/sale-estimates/{id}/sms-details',
|
||||
MAIL: '/api/sale-estimates/{id}/mail',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
type GetSaleEstimates = paths[typeof SALE_ESTIMATES_ROUTES.LIST]['get'];
|
||||
@@ -55,3 +61,82 @@ export async function deleteSaleEstimate(fetcher: ApiFetcher, id: number): Promi
|
||||
const del = fetcher.path(SALE_ESTIMATES_ROUTES.BY_ID).method('delete').create();
|
||||
await del({ id });
|
||||
}
|
||||
|
||||
export type BulkDeleteEstimatesBody = { ids: number[]; skipUndeletable?: boolean };
|
||||
export type ValidateBulkDeleteEstimatesResponse = {
|
||||
deletableCount: number;
|
||||
nonDeletableCount: number;
|
||||
deletableIds: number[];
|
||||
nonDeletableIds: number[];
|
||||
};
|
||||
|
||||
export async function bulkDeleteSaleEstimates(
|
||||
fetcher: ApiFetcher,
|
||||
body: BulkDeleteEstimatesBody
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(SALE_ESTIMATES_ROUTES.BULK_DELETE).method('post').create();
|
||||
await post({ ids: body.ids, skipUndeletable: body.skipUndeletable ?? false } as never);
|
||||
}
|
||||
|
||||
export async function validateBulkDeleteSaleEstimates(
|
||||
fetcher: ApiFetcher,
|
||||
ids: number[]
|
||||
): Promise<ValidateBulkDeleteEstimatesResponse> {
|
||||
const post = fetcher.path(SALE_ESTIMATES_ROUTES.VALIDATE_BULK_DELETE).method('post').create();
|
||||
const { data } = await post({ ids, skipUndeletable: false } as never);
|
||||
return data as ValidateBulkDeleteEstimatesResponse;
|
||||
}
|
||||
|
||||
export async function deliverSaleEstimate(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const post = fetcher.path(SALE_ESTIMATES_ROUTES.DELIVER).method('post').create();
|
||||
await post({ id });
|
||||
}
|
||||
|
||||
export async function approveSaleEstimate(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const put = fetcher.path(SALE_ESTIMATES_ROUTES.APPROVE).method('put').create();
|
||||
await put({ id });
|
||||
}
|
||||
|
||||
export async function rejectSaleEstimate(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const put = fetcher.path(SALE_ESTIMATES_ROUTES.REJECT).method('put').create();
|
||||
await put({ id });
|
||||
}
|
||||
|
||||
export async function notifySaleEstimateBySms(
|
||||
fetcher: ApiFetcher,
|
||||
id: number,
|
||||
body?: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(SALE_ESTIMATES_ROUTES.NOTIFY_SMS).method('post').create();
|
||||
await post({ id, ...(body ?? {}) } as never);
|
||||
}
|
||||
|
||||
export async function fetchSaleEstimateSmsDetails(
|
||||
fetcher: ApiFetcher,
|
||||
id: number
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(SALE_ESTIMATES_ROUTES.SMS_DETAILS).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchSaleEstimateMail(fetcher: ApiFetcher, id: number): Promise<unknown> {
|
||||
const get = fetcher.path(SALE_ESTIMATES_ROUTES.MAIL).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function sendSaleEstimateMail(
|
||||
fetcher: ApiFetcher,
|
||||
id: number,
|
||||
body?: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(SALE_ESTIMATES_ROUTES.MAIL).method('post').create();
|
||||
await post({ id, ...(body ?? {}) } as never);
|
||||
}
|
||||
|
||||
export async function fetchSaleEstimatesState(fetcher: ApiFetcher): Promise<unknown> {
|
||||
const get = fetcher.path(SALE_ESTIMATES_ROUTES.STATE).method('get').create();
|
||||
const { data } = await get({});
|
||||
return data;
|
||||
}
|
||||
|
||||
66
shared/sdk-ts/src/tax-rates.ts
Normal file
66
shared/sdk-ts/src/tax-rates.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { ApiFetcher } from './fetch-utils';
|
||||
import type { paths } from './schema';
|
||||
|
||||
export const TAX_RATES_ROUTES = {
|
||||
LIST: '/api/tax-rates',
|
||||
BY_ID: '/api/tax-rates/{id}',
|
||||
ACTIVATE: '/api/tax-rates/{id}/activate',
|
||||
INACTIVATE: '/api/tax-rates/{id}/inactivate',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
type GetTaxRates = paths[typeof TAX_RATES_ROUTES.LIST]['get'];
|
||||
type GetTaxRate = paths[typeof TAX_RATES_ROUTES.BY_ID]['get'];
|
||||
type CreateTaxRate = paths[typeof TAX_RATES_ROUTES.LIST]['post'];
|
||||
type EditTaxRate = paths[typeof TAX_RATES_ROUTES.BY_ID]['put'];
|
||||
type DeleteTaxRate = paths[typeof TAX_RATES_ROUTES.BY_ID]['delete'];
|
||||
|
||||
type GetTaxRates200 = GetTaxRates['responses'][200];
|
||||
type GetTaxRate200 = GetTaxRate['responses'][200];
|
||||
export type TaxRatesListResponse = GetTaxRates200 extends { content?: { 'application/json': infer J } } ? J : unknown;
|
||||
export type TaxRate = GetTaxRate200 extends { content?: { 'application/json': infer J } } ? J : unknown;
|
||||
export type CreateTaxRateBody = CreateTaxRate extends { requestBody: { content: { 'application/json': infer J } } } ? J : Record<string, unknown>;
|
||||
export type EditTaxRateBody = EditTaxRate extends { requestBody: { content: { 'application/json': infer J } } } ? J : Record<string, unknown>;
|
||||
|
||||
export async function fetchTaxRates(fetcher: ApiFetcher): Promise<TaxRatesListResponse> {
|
||||
const get = fetcher.path(TAX_RATES_ROUTES.LIST).method('get').create();
|
||||
const { data } = await get({});
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchTaxRate(fetcher: ApiFetcher, id: number): Promise<TaxRate> {
|
||||
const get = fetcher.path(TAX_RATES_ROUTES.BY_ID).method('get').create();
|
||||
const { data } = await get({ id });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createTaxRate(
|
||||
fetcher: ApiFetcher,
|
||||
values: CreateTaxRateBody
|
||||
): Promise<void> {
|
||||
const post = fetcher.path(TAX_RATES_ROUTES.LIST).method('post').create();
|
||||
await post(values as never);
|
||||
}
|
||||
|
||||
export async function editTaxRate(
|
||||
fetcher: ApiFetcher,
|
||||
id: string,
|
||||
values: EditTaxRateBody
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(TAX_RATES_ROUTES.BY_ID).method('put').create();
|
||||
await put({ id, ...values } as never);
|
||||
}
|
||||
|
||||
export async function deleteTaxRate(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const del = fetcher.path(TAX_RATES_ROUTES.BY_ID).method('delete').create();
|
||||
await del({ id });
|
||||
}
|
||||
|
||||
export async function activateTaxRate(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const put = fetcher.path(TAX_RATES_ROUTES.ACTIVATE).method('put').create();
|
||||
await put({ id });
|
||||
}
|
||||
|
||||
export async function inactivateTaxRate(fetcher: ApiFetcher, id: number): Promise<void> {
|
||||
const put = fetcher.path(TAX_RATES_ROUTES.INACTIVATE).method('put').create();
|
||||
await put({ id });
|
||||
}
|
||||
@@ -10,15 +10,51 @@ export const TRANSACTIONS_LOCKING_ROUTES = {
|
||||
BY_MODULE: '/api/transactions-locking/{module}',
|
||||
} as const satisfies Record<string, keyof paths>;
|
||||
|
||||
export async function fetchTransactionsLocking(fetcher: ApiFetcher): Promise<void> {
|
||||
export type TransactionsLockingListResponse = unknown;
|
||||
|
||||
export async function fetchTransactionsLocking(fetcher: ApiFetcher): Promise<TransactionsLockingListResponse> {
|
||||
const get = fetcher.path(TRANSACTIONS_LOCKING_ROUTES.LIST).method('get').create();
|
||||
await get({});
|
||||
const { data } = await get({});
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchTransactionsLockingByModule(
|
||||
fetcher: ApiFetcher,
|
||||
module: string
|
||||
): Promise<void> {
|
||||
): Promise<unknown> {
|
||||
const get = fetcher.path(TRANSACTIONS_LOCKING_ROUTES.BY_MODULE).method('get').create();
|
||||
await get({ module });
|
||||
const { data } = await get({ module });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function lockTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
values: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(TRANSACTIONS_LOCKING_ROUTES.LOCK).method('put').create();
|
||||
await put(values as never);
|
||||
}
|
||||
|
||||
export async function cancelLockTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
values: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(TRANSACTIONS_LOCKING_ROUTES.CANCEL_LOCK).method('put').create();
|
||||
await put(values as never);
|
||||
}
|
||||
|
||||
export async function unlockPartialTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
values: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(TRANSACTIONS_LOCKING_ROUTES.UNLOCK_PARTIAL).method('put').create();
|
||||
await put(values as never);
|
||||
}
|
||||
|
||||
export async function cancelUnlockPartialTransactions(
|
||||
fetcher: ApiFetcher,
|
||||
values: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const put = fetcher.path(TRANSACTIONS_LOCKING_ROUTES.CANCEL_UNLOCK_PARTIAL).method('put').create();
|
||||
await put(values as never);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user