From dddeb25923082b5d8b250300197dcdf4bded97ee Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Mon, 9 Mar 2026 06:35:03 +0200 Subject: [PATCH] feat(sdk-ts): add Payment Links, Stripe Integration, Plaid, Import and additional modules --- shared/sdk-ts/src/bank-rules.ts | 13 +-- shared/sdk-ts/src/credit-notes.ts | 12 ++- shared/sdk-ts/src/customers.ts | 12 +++ shared/sdk-ts/src/import.ts | 70 ++++++++++++++ shared/sdk-ts/src/index.ts | 7 ++ shared/sdk-ts/src/inventory-cost.ts | 34 +++++++ shared/sdk-ts/src/landed-cost.ts | 32 ++++++- shared/sdk-ts/src/organization.ts | 22 +++++ shared/sdk-ts/src/payment-links.ts | 72 ++++++++++++++ shared/sdk-ts/src/payment-mades.ts | 18 ++++ shared/sdk-ts/src/payment-services.ts | 120 ++++++++++++++++++++++++ shared/sdk-ts/src/plaid.ts | 40 ++++++++ shared/sdk-ts/src/schema.ts | 74 +++++++++++++++ shared/sdk-ts/src/stripe-integration.ts | 102 ++++++++++++++++++++ shared/sdk-ts/src/subscription.ts | 22 ++++- shared/sdk-ts/src/vendor-credits.ts | 2 +- shared/sdk-ts/src/vendors.ts | 12 +++ 17 files changed, 653 insertions(+), 11 deletions(-) create mode 100644 shared/sdk-ts/src/import.ts create mode 100644 shared/sdk-ts/src/inventory-cost.ts create mode 100644 shared/sdk-ts/src/payment-links.ts create mode 100644 shared/sdk-ts/src/payment-services.ts create mode 100644 shared/sdk-ts/src/plaid.ts create mode 100644 shared/sdk-ts/src/stripe-integration.ts diff --git a/shared/sdk-ts/src/bank-rules.ts b/shared/sdk-ts/src/bank-rules.ts index 38b9370f0..4f7a1113d 100644 --- a/shared/sdk-ts/src/bank-rules.ts +++ b/shared/sdk-ts/src/bank-rules.ts @@ -276,10 +276,11 @@ export async function uncategorizeTransactionsBulk( const del = fetcher .path(BANK_RULES_ROUTES.CATEGORIZE_BULK) .method('delete') - .create(); - await (del as (params: { - query?: { uncategorizedTransactionIds: number[] }; - }) => Promise)({ - query: { uncategorizedTransactionIds }, - }); + .create( + { uncategorizedTransactionIds } as unknown as { + uncategorizedTransactionIds: true | 1; + }, + ); + // create() binds query; call with no args (params were passed to create()) + await (del as unknown as () => Promise)(); } diff --git a/shared/sdk-ts/src/credit-notes.ts b/shared/sdk-ts/src/credit-notes.ts index dd3297efd..4704b7293 100644 --- a/shared/sdk-ts/src/credit-notes.ts +++ b/shared/sdk-ts/src/credit-notes.ts @@ -44,9 +44,17 @@ export async function fetchCreditNote(fetcher: ApiFetcher, id: number): Promise< return data; } -export async function fetchCreditNoteState(fetcher: ApiFetcher): Promise { +/** Credit note state (default template etc.). Defined in controller DTO when not in schema. */ +export interface CreditNoteStateResponse { + defaultTemplateId: number; +} + +export async function fetchCreditNoteState( + fetcher: ApiFetcher +): Promise { const getState = fetcher.path(CREDIT_NOTES_ROUTES.STATE).method('get').create(); - await getState({}); + const { data } = await getState({}); + return (data ?? { defaultTemplateId: 0 }) as CreditNoteStateResponse; } export async function createCreditNote( diff --git a/shared/sdk-ts/src/customers.ts b/shared/sdk-ts/src/customers.ts index 394514c39..0415dc70a 100644 --- a/shared/sdk-ts/src/customers.ts +++ b/shared/sdk-ts/src/customers.ts @@ -17,6 +17,8 @@ export type EditCustomerBody = OpRequestBody>; export type BulkDeleteCustomersBody = OpRequestBody>; export type GetCustomersQuery = OpQueryParams>; +export type EditCustomerOpeningBalanceBody = OpRequestBody>; +export type EditCustomerOpeningBalanceResponse = OpResponseBody>; export async function fetchCustomers( fetcher: ApiFetcher, @@ -73,3 +75,13 @@ export async function bulkDeleteCustomers( const post = fetcher.path(CUSTOMERS_ROUTES.BULK_DELETE).method('post').create(); await post(body); } + +export async function editCustomerOpeningBalance( + fetcher: ApiFetcher, + id: number, + values: EditCustomerOpeningBalanceBody +): Promise { + const put = fetcher.path(CUSTOMERS_ROUTES.OPENING_BALANCE).method('put').create(); + const { data } = await put({ id, ...values }); + return data; +} diff --git a/shared/sdk-ts/src/import.ts b/shared/sdk-ts/src/import.ts new file mode 100644 index 000000000..676d0979d --- /dev/null +++ b/shared/sdk-ts/src/import.ts @@ -0,0 +1,70 @@ +import type { ApiFetcher } from './fetch-utils'; +import { paths } from './schema'; + +export const IMPORT_ROUTES = { + FILE: '/api/import/file', + MAPPING: '/api/import/{import_id}/mapping', + PREVIEW: '/api/import/{import_id}/preview', + IMPORT: '/api/import/{import_id}/import', + SAMPLE: '/api/import/sample', + META: '/api/import/{import_id}', +} as const satisfies Record; + +export interface ImportMappingBody { + mapping: Array<{ group?: string; from: string; to: string }>; +} + +export interface ImportPreviewResponse { + [key: string]: unknown; +} + +export interface ImportFileMetaResponse { + [key: string]: unknown; +} + +export interface ImportProcessResponse { + resource?: string; + [key: string]: unknown; +} + +export async function fetchImportPreview( + fetcher: ApiFetcher, + importId: string +): Promise { + const get = fetcher + .path(IMPORT_ROUTES.PREVIEW) + .method('get') + .create(); + const { data } = await get({ import_id: importId } as never); + return (data ?? {}) as ImportPreviewResponse; +} + +export async function fetchImportFileMeta( + fetcher: ApiFetcher, + importId: string +): Promise { + const get = fetcher.path(IMPORT_ROUTES.META).method('get').create(); + const { data } = await get({ import_id: importId } as never); + return (data ?? {}) as ImportFileMetaResponse; +} + +export async function importMapping( + fetcher: ApiFetcher, + importId: string, + body: ImportMappingBody +): Promise { + const post = fetcher + .path(IMPORT_ROUTES.MAPPING) + .method('post') + .create(); + await post({ import_id: importId, ...body } as never); +} + +export async function importProcess( + fetcher: ApiFetcher, + importId: string +): Promise { + const post = fetcher.path(IMPORT_ROUTES.IMPORT).method('post').create(); + const { data } = await post({ import_id: importId } as never); + return (data ?? {}) as ImportProcessResponse; +} diff --git a/shared/sdk-ts/src/index.ts b/shared/sdk-ts/src/index.ts index 622a4e47e..fd59809c8 100644 --- a/shared/sdk-ts/src/index.ts +++ b/shared/sdk-ts/src/index.ts @@ -15,10 +15,12 @@ export * from './items'; export * from './branches'; export * from './warehouses'; export * from './expenses'; +export * from './import'; export * from './manual-journals'; export * from './roles'; export * from './users'; export * from './dashboard'; +export * from './export'; export * from './settings'; export * from './organization'; export * from './subscription'; @@ -37,7 +39,12 @@ export * from './sale-estimates'; export * from './sale-receipts'; export * from './payment-receives'; export * from './payment-mades'; +export * from './payment-links'; +export * from './payment-services'; +export * from './plaid'; +export * from './stripe-integration'; export * from './inventory-adjustments'; +export * from './inventory-cost'; export * from './warehouse-transfers'; export * from './landed-cost'; export * from './generic-resource'; diff --git a/shared/sdk-ts/src/inventory-cost.ts b/shared/sdk-ts/src/inventory-cost.ts new file mode 100644 index 000000000..9aca6d6c9 --- /dev/null +++ b/shared/sdk-ts/src/inventory-cost.ts @@ -0,0 +1,34 @@ +import type { OpArgType } from 'openapi-typescript-fetch'; +import type { ApiFetcher } from './fetch-utils'; +import { paths } from './schema'; +import { OpForPath, OpQueryParams } from './utils'; + +export const INVENTORY_COST_ROUTES = { + ITEMS: '/api/inventory-cost/items', +} as const satisfies Record; + +type GetItemsCostOp = OpForPath; +type GetItemsCostArg = OpArgType; + +/** Query params for get items inventory cost. */ +export type GetInventoryItemsCostQuery = OpQueryParams; + +export interface InventoryItemCostMeta { + itemId: number; + valuation: number; + quantity: number; + average: number; +} + +export interface GetInventoryItemsCostResponse { + costs: InventoryItemCostMeta[]; +} + +export async function fetchInventoryCostItems( + fetcher: ApiFetcher, + query: GetInventoryItemsCostQuery +): Promise { + const get = fetcher.path(INVENTORY_COST_ROUTES.ITEMS).method('get').create(); + const { data } = await get(query as GetItemsCostArg); + return (data ?? { costs: [] }) as GetInventoryItemsCostResponse; +} diff --git a/shared/sdk-ts/src/landed-cost.ts b/shared/sdk-ts/src/landed-cost.ts index 32790bfe5..88e763eb7 100644 --- a/shared/sdk-ts/src/landed-cost.ts +++ b/shared/sdk-ts/src/landed-cost.ts @@ -1,6 +1,6 @@ import type { ApiFetcher } from './fetch-utils'; import { paths } from './schema'; -import { OpForPath, OpQueryParams, OpResponseBody } from './utils'; +import { OpForPath, OpQueryParams, OpRequestBody, OpResponseBody } from './utils'; export const LANDED_COST_ROUTES = { TRANSACTIONS: '/api/landed-cost/transactions', @@ -11,6 +11,10 @@ export const LANDED_COST_ROUTES = { export type LandedCostTransactionsResponse = OpResponseBody>; export type GetLandedCostTransactionsQuery = OpQueryParams>; +export type AllocateLandedCostBody = OpRequestBody>; +export type BillLandedCostTransactionsResponse = OpResponseBody< + OpForPath +>; export async function fetchLandedCostTransactions( fetcher: ApiFetcher, @@ -22,3 +26,29 @@ export async function fetchLandedCostTransactions( )(query ?? {}); return data; } + +export async function allocateLandedCost( + fetcher: ApiFetcher, + billId: number, + body: AllocateLandedCostBody +): Promise { + const post = fetcher.path(LANDED_COST_ROUTES.ALLOCATE).method('post').create(); + await post({ billId, ...body } as never); +} + +export async function deleteAllocatedLandedCost( + fetcher: ApiFetcher, + allocatedLandedCostId: number +): Promise { + const del = fetcher.path(LANDED_COST_ROUTES.BY_ID).method('delete').create(); + await del({ allocatedLandedCostId }); +} + +export async function fetchBillLandedCostTransactions( + fetcher: ApiFetcher, + billId: number +): Promise { + const get = fetcher.path(LANDED_COST_ROUTES.BILL_TRANSACTIONS).method('get').create(); + const { data } = await get({ billId }); + return data; +} diff --git a/shared/sdk-ts/src/organization.ts b/shared/sdk-ts/src/organization.ts index 997352837..3c1ed0243 100644 --- a/shared/sdk-ts/src/organization.ts +++ b/shared/sdk-ts/src/organization.ts @@ -12,6 +12,11 @@ export const ORGANIZATION_ROUTES = { export type OrganizationCurrent = OpResponseBody>; export type UpdateOrganizationBody = OpRequestBody>; +export type BuildOrganizationBody = OpRequestBody>; +export type BuildOrganizationResponse = OpResponseBody>; +export type OrgBaseCurrencyMutateAbilitiesResponse = OpResponseBody< + OpForPath +>; export async function fetchOrganizationCurrent(fetcher: ApiFetcher): Promise { const get = fetcher.path(ORGANIZATION_ROUTES.CURRENT).method('get').create(); @@ -19,6 +24,23 @@ export async function fetchOrganizationCurrent(fetcher: ApiFetcher): Promise { + const post = fetcher.path(ORGANIZATION_ROUTES.BUILD).method('post').create(); + const { data } = await post(values as never); + return data; +} + +export async function fetchOrgBaseCurrencyMutateAbilities( + fetcher: ApiFetcher +): Promise { + const get = fetcher.path(ORGANIZATION_ROUTES.BASE_CURRENCY_MUTATE).method('get').create(); + const { data } = await get({}); + return data; +} + export async function updateOrganization( fetcher: ApiFetcher, values: UpdateOrganizationBody diff --git a/shared/sdk-ts/src/payment-links.ts b/shared/sdk-ts/src/payment-links.ts new file mode 100644 index 000000000..ebaa34915 --- /dev/null +++ b/shared/sdk-ts/src/payment-links.ts @@ -0,0 +1,72 @@ +import type { ApiFetcher } from './fetch-utils'; +import { paths } from './schema'; +import { OpForPath, OpResponseBody, OpResponseBodyPdf } from './utils'; + +export const PAYMENT_LINKS_ROUTES = { + GET_INVOICE: '/api/payment-links/{paymentLinkId}/invoice', + CREATE_STRIPE_CHECKOUT_SESSION: + '/api/payment-links/{paymentLinkId}/stripe_checkout_session', + GET_INVOICE_PDF: '/api/payment-links/{paymentLinkId}/invoice/pdf', +} as const satisfies Record; + +type GetInvoiceOp = OpForPath< + (typeof PAYMENT_LINKS_ROUTES)['GET_INVOICE'], + 'get' +>; +type CreateCheckoutSessionOp = OpForPath< + (typeof PAYMENT_LINKS_ROUTES)['CREATE_STRIPE_CHECKOUT_SESSION'], + 'post' +>; +type GetInvoicePdfOp = OpForPath< + (typeof PAYMENT_LINKS_ROUTES)['GET_INVOICE_PDF'], + 'get' +>; + +export type GetInvoicePaymentLinkResponse = GetInvoiceOp extends { + responses: { 200: { content: { 'application/json': infer R } } }; +} + ? R extends { data?: infer D } + ? D + : R + : unknown; + +export type CreateStripeCheckoutSessionResponse = + OpResponseBody; +export type GetPaymentLinkInvoicePdfResponse = OpResponseBodyPdf; + +export async function fetchGetInvoicePaymentLink( + fetcher: ApiFetcher, + paymentLinkId: string, +): Promise { + const get = fetcher + .path(PAYMENT_LINKS_ROUTES.GET_INVOICE) + .method('get') + .create(); + const { data } = await get({ paymentLinkId }); + const body = data as { data?: GetInvoicePaymentLinkResponse }; + return body?.data ?? (body as GetInvoicePaymentLinkResponse); +} + +export async function fetchCreateStripeCheckoutSession( + fetcher: ApiFetcher, + paymentLinkId: string, +): Promise { + const post = fetcher + .path(PAYMENT_LINKS_ROUTES.CREATE_STRIPE_CHECKOUT_SESSION) + .method('post') + .create(); + const { data } = await post({ paymentLinkId }); + return data as CreateStripeCheckoutSessionResponse; +} + +export async function fetchGetPaymentLinkInvoicePdf( + fetcher: ApiFetcher, + paymentLinkId: string, +): Promise { + const get = fetcher + .path(PAYMENT_LINKS_ROUTES.GET_INVOICE_PDF) + .method('get') + .create(); + const response = await get({ paymentLinkId }); + return (response.data as Blob) ?? response.data; +} diff --git a/shared/sdk-ts/src/payment-mades.ts b/shared/sdk-ts/src/payment-mades.ts index b1ae0a703..840a03722 100644 --- a/shared/sdk-ts/src/payment-mades.ts +++ b/shared/sdk-ts/src/payment-mades.ts @@ -57,3 +57,21 @@ export async function fetchBillPaymentEditPage( const { data } = await get({ billPaymentId }); return data; } + +export type BillPaymentNewPageEntriesResponse = unknown; + +export async function fetchBillPaymentNewPageEntries( + fetcher: ApiFetcher, + vendorId: number +): Promise { + const get = fetcher + .path(BILL_PAYMENTS_ROUTES.NEW_PAGE_ENTRIES) + .method('get') + .create(); + + const { data } = await ( + // @ts-ignore + get as (params: { query?: { vendorId: number } }) => Promise<{ data: BillPaymentNewPageEntriesResponse }> + )({ query: { vendorId } }); + return data; +} diff --git a/shared/sdk-ts/src/payment-services.ts b/shared/sdk-ts/src/payment-services.ts new file mode 100644 index 000000000..ba195bbb0 --- /dev/null +++ b/shared/sdk-ts/src/payment-services.ts @@ -0,0 +1,120 @@ +import type { ApiFetcher } from './fetch-utils'; +import { paths } from './schema'; + +export const PAYMENT_SERVICES_ROUTES = { + LIST: '/api/payment-services', + STATE: '/api/payment-services/state', + BY_ID: '/api/payment-services/{paymentServiceId}', + UPDATE_METHOD: '/api/payment-services/{paymentMethodId}', + DELETE_METHOD: '/api/payment-services/{paymentMethodId}', +} as const satisfies Record; + +export interface GetPaymentServicesResponse { + payment_services?: unknown; +} + +export interface GetPaymentServicesStateResponse { + stripe: { + is_stripe_account_created: boolean; + is_stripe_payment_enabled: boolean; + is_stripe_payout_enabled: boolean; + is_stripe_enabled: boolean; + is_stripe_server_configured: boolean; + stripe_account_id: string | null; + stripe_payment_method_id: number | null; + stripe_currencies: string[]; + stripe_publishable_key: string; + stripe_auth_link: string; + stripe_redirect_url: string; + }; +} + +export interface GetPaymentServiceResponse { + data?: unknown; +} + +export interface EditPaymentMethodOptionsBody { + bankAccountId?: number; + clearningAccountId?: number; + showVisa?: boolean; + showMasterCard?: boolean; + showDiscover?: boolean; + showAmer?: boolean; + showJcb?: boolean; + showDiners?: boolean; +} + +export interface UpdatePaymentMethodBody { + name?: string; + options?: EditPaymentMethodOptionsBody; +} + +export interface UpdatePaymentMethodResponse { + id: number; + message: string; +} + +export interface DeletePaymentMethodResponse { + id: number; + message: string; +} + +export async function fetchGetPaymentServices( + fetcher: ApiFetcher, +): Promise { + const get = fetcher + .path(PAYMENT_SERVICES_ROUTES.LIST) + .method('get') + .create(); + const { data } = await get({}); + return data as GetPaymentServicesResponse; +} + +export async function fetchGetPaymentServicesState( + fetcher: ApiFetcher, +): Promise { + const get = fetcher + .path(PAYMENT_SERVICES_ROUTES.STATE) + .method('get') + .create(); + const { data } = await get({}); + const wrapped = data as { data?: GetPaymentServicesStateResponse }; + return wrapped?.data ?? (data as GetPaymentServicesStateResponse); +} + +export async function fetchGetPaymentService( + fetcher: ApiFetcher, + paymentServiceId: number, +): Promise { + const get = fetcher + .path(PAYMENT_SERVICES_ROUTES.BY_ID) + .method('get') + .create(); + const { data } = await get({ paymentServiceId }); + return data as GetPaymentServiceResponse; +} + +export async function fetchUpdatePaymentMethod( + fetcher: ApiFetcher, + paymentMethodId: number, + body: UpdatePaymentMethodBody, +): Promise { + const post = fetcher + .path(PAYMENT_SERVICES_ROUTES.UPDATE_METHOD) + .method('post') + .create(); + const { data } = await post({ paymentMethodId, ...body } as never); + return data as UpdatePaymentMethodResponse; +} + +export async function fetchDeletePaymentMethod( + fetcher: ApiFetcher, + paymentMethodId: number, +): Promise { + const del = fetcher + .path(PAYMENT_SERVICES_ROUTES.DELETE_METHOD) + .method('delete') + .create(); + const { data } = await del({ paymentMethodId }); + return data as DeletePaymentMethodResponse; +} diff --git a/shared/sdk-ts/src/plaid.ts b/shared/sdk-ts/src/plaid.ts new file mode 100644 index 000000000..dbd220a73 --- /dev/null +++ b/shared/sdk-ts/src/plaid.ts @@ -0,0 +1,40 @@ +import type { ApiFetcher } from './fetch-utils'; +import { paths } from './schema'; + +export const PLAID_ROUTES = { + LINK_TOKEN: '/api/banking/plaid/link-token', + EXCHANGE_TOKEN: '/api/banking/plaid/exchange-token', +} as const satisfies Record; + +export interface PlaidLinkTokenResponse { + linkToken?: string; + [key: string]: unknown; +} + +export interface PlaidExchangeTokenBody { + publicToken: string; + institutionId?: string; + [key: string]: unknown; +} + +export async function fetchPlaidLinkToken( + fetcher: ApiFetcher +): Promise { + const post = fetcher + .path(PLAID_ROUTES.LINK_TOKEN) + .method('post') + .create(); + const { data } = await post({}); + return (data ?? {}) as PlaidLinkTokenResponse; +} + +export async function fetchPlaidExchangeToken( + fetcher: ApiFetcher, + body: PlaidExchangeTokenBody +): Promise { + const post = fetcher + .path(PLAID_ROUTES.EXCHANGE_TOKEN) + .method('post') + .create(); + await post(body as never); +} diff --git a/shared/sdk-ts/src/schema.ts b/shared/sdk-ts/src/schema.ts index 79fad9f3c..52bbc6584 100644 --- a/shared/sdk-ts/src/schema.ts +++ b/shared/sdk-ts/src/schema.ts @@ -1580,6 +1580,38 @@ export interface paths { patch?: never; trace?: never; }; + "/api/stripe/account": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + post: operations["StripeIntegrationController_createAccount"]; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + "/api/stripe/account_session": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + post: operations["StripeIntegrationController_createAccountSession"]; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/webhooks/stripe": { parameters: { query?: never; @@ -17130,6 +17162,48 @@ export interface operations { }; }; }; + StripeIntegrationController_createAccount: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + 201: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { account_id: string }; + }; + }; + }; + }; + StripeIntegrationController_createAccountSession: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { account?: string }; + }; + }; + responses: { + 201: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { client_secret: string }; + }; + }; + }; + }; StripePaymentWebhooksController_handleWebhook: { parameters: { query?: never; diff --git a/shared/sdk-ts/src/stripe-integration.ts b/shared/sdk-ts/src/stripe-integration.ts new file mode 100644 index 000000000..ffc46175c --- /dev/null +++ b/shared/sdk-ts/src/stripe-integration.ts @@ -0,0 +1,102 @@ +import type { ApiFetcher } from './fetch-utils'; +import { paths } from './schema'; + +export const STRIPE_INTEGRATION_ROUTES = { + GET_LINK: '/api/stripe/link', + CALLBACK: '/api/stripe/callback', + ACCOUNT_LINK: '/api/stripe/account_link', + ACCOUNT: '/api/stripe/account', + ACCOUNT_SESSION: '/api/stripe/account_session', +} as const; + +export interface GetStripeConnectLinkResponse { + url: string; +} + +export interface ExchangeStripeOAuthBody { + code: string; +} + +export interface CreateStripeAccountLinkBody { + stripeAccountId: string; +} + +export interface StripeAccountLinkResponse { + url: string; + created: number; + expires_at: number; + object: string; +} + +export interface CreateStripeAccountLinkResponse { + clientSecret: StripeAccountLinkResponse; +} + +export async function fetchGetStripeConnectLink( + fetcher: ApiFetcher, +): Promise { + const get = fetcher + .path(STRIPE_INTEGRATION_ROUTES.GET_LINK) + .method('get') + .create(); + const { data } = await get({}); + return data as GetStripeConnectLinkResponse; +} + +export async function fetchExchangeStripeOAuth( + fetcher: ApiFetcher, + body: ExchangeStripeOAuthBody, +): Promise { + const post = fetcher + .path(STRIPE_INTEGRATION_ROUTES.CALLBACK) + .method('post') + .create(); + await post(body as never); +} + +export async function fetchCreateStripeAccountLink( + fetcher: ApiFetcher, + body: CreateStripeAccountLinkBody, +): Promise { + const post = fetcher + .path(STRIPE_INTEGRATION_ROUTES.ACCOUNT_LINK) + .method('post') + .create(); + const { data } = await post(body as never); + return data as CreateStripeAccountLinkResponse; +} + +export interface CreateStripeAccountResponse { + account_id: string; +} + +export interface CreateStripeAccountSessionBody { + account?: string; +} + +export interface CreateStripeAccountSessionResponse { + client_secret: string; +} + +export async function fetchCreateStripeAccount( + fetcher: ApiFetcher, +): Promise { + const post = fetcher + .path(STRIPE_INTEGRATION_ROUTES.ACCOUNT) + .method('post') + .create(); + const { data } = await post({}); + return data as CreateStripeAccountResponse; +} + +export async function fetchCreateStripeAccountSession( + fetcher: ApiFetcher, + body: CreateStripeAccountSessionBody, +): Promise { + const post = fetcher + .path(STRIPE_INTEGRATION_ROUTES.ACCOUNT_SESSION) + .method('post') + .create(); + const { data } = await post(body as never); + return data as CreateStripeAccountSessionResponse; +} diff --git a/shared/sdk-ts/src/subscription.ts b/shared/sdk-ts/src/subscription.ts index 7b7379d95..8457a0b00 100644 --- a/shared/sdk-ts/src/subscription.ts +++ b/shared/sdk-ts/src/subscription.ts @@ -1,6 +1,6 @@ import type { ApiFetcher } from './fetch-utils'; import { paths } from './schema'; -import { OpForPath, OpResponseBody } from './utils'; +import { OpForPath, OpRequestBody, OpResponseBody } from './utils'; export const SUBSCRIPTION_ROUTES = { LIST: '/api/subscription', @@ -11,6 +11,9 @@ export const SUBSCRIPTION_ROUTES = { } as const satisfies Record; export type SubscriptionsListResponse = OpResponseBody>; +export type ChangeSubscriptionPlanBody = OpRequestBody>; +export type GetLemonCheckoutUrlBody = OpRequestBody>; +export type GetLemonCheckoutUrlResponse = OpResponseBody>; export async function fetchSubscriptions(fetcher: ApiFetcher): Promise { const get = fetcher.path(SUBSCRIPTION_ROUTES.LIST).method('get').create(); @@ -18,6 +21,15 @@ export async function fetchSubscriptions(fetcher: ApiFetcher): Promise { + const post = fetcher.path(SUBSCRIPTION_ROUTES.CHECKOUT_URL).method('post').create(); + const { data } = await post(body as never); + return data; +} + export async function cancelSubscription(fetcher: ApiFetcher): Promise { const post = fetcher.path(SUBSCRIPTION_ROUTES.CANCEL).method('post').create(); await post({}); @@ -27,3 +39,11 @@ export async function resumeSubscription(fetcher: ApiFetcher): Promise { const post = fetcher.path(SUBSCRIPTION_ROUTES.RESUME).method('post').create(); await post({}); } + +export async function changeSubscriptionPlan( + fetcher: ApiFetcher, + body: ChangeSubscriptionPlanBody +): Promise { + const post = fetcher.path(SUBSCRIPTION_ROUTES.CHANGE).method('post').create(); + await post(body as never); +} diff --git a/shared/sdk-ts/src/vendor-credits.ts b/shared/sdk-ts/src/vendor-credits.ts index 69bf04196..047bf7b35 100644 --- a/shared/sdk-ts/src/vendor-credits.ts +++ b/shared/sdk-ts/src/vendor-credits.ts @@ -154,7 +154,7 @@ export async function fetchRefundVendorCreditTransaction( .path(VENDOR_CREDITS_ROUTES.REFUND_BY_ID) .method('get') .create(); - const { data } = await get({ refundCreditId }); + const { data } = await get({ refundCreditId: String(refundCreditId) }); return data; } diff --git a/shared/sdk-ts/src/vendors.ts b/shared/sdk-ts/src/vendors.ts index f399995af..43983f4f6 100644 --- a/shared/sdk-ts/src/vendors.ts +++ b/shared/sdk-ts/src/vendors.ts @@ -17,6 +17,8 @@ export type EditVendorBody = OpRequestBody>; export type BulkDeleteVendorsBody = OpRequestBody>; export type GetVendorsQuery = OpQueryParams>; +export type EditVendorOpeningBalanceBody = OpRequestBody>; +export type EditVendorOpeningBalanceResponse = OpResponseBody>; export async function fetchVendors( fetcher: ApiFetcher, @@ -73,3 +75,13 @@ export async function bulkDeleteVendors( const post = fetcher.path(VENDORS_ROUTES.BULK_DELETE).method('post').create(); await post(body); } + +export async function editVendorOpeningBalance( + fetcher: ApiFetcher, + id: number, + values: EditVendorOpeningBalanceBody +): Promise { + const put = fetcher.path(VENDORS_ROUTES.OPENING_BALANCE).method('put').create(); + const { data } = await put({ id, ...values }); + return data; +}