import {z} from 'zod' export type FireAntApiModelsIRIROaAccountChangeRequest = {userName?: string | undefined, displayName?: string | undefined, bio?: string | undefined, avatarUrl?: string | undefined, coverUrl?: string | undefined, verificationDocUrl?: string | undefined, autoDraftDisclosures?: boolean | undefined, commentMode?: (0 | 1 | 2) | undefined, requireApproval?: boolean | undefined}; export type CreateApiIrSymbolOfficialAccountClaimArgs = {symbol: string, body: FireAntApiModelsIRIROaAccountChangeRequest}; export type CreateApiIrSymbolOfficialAccountClaimOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fireAntApiModelsIRIROaAccount = z.object({companyId: z.number().int().optional(), symbol: z.string().optional(), companyName: z.string().optional(), userName: z.string().optional(), displayName: z.string().optional(), bio: z.string().optional(), avatarUrl: z.string().optional(), coverUrl: z.string().optional(), verificationDocUrl: z.string().optional(), verifiedDate: z.string().optional(), verifiedBy: z.string().optional(), status: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]).optional(), rejectReason: z.string().optional(), autoDraftDisclosures: z.boolean().optional(), commentMode: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(), requireApproval: z.boolean().optional(), defaultLanguage: z.string().optional(), createdBy: z.string().optional(), createdDate: z.string().optional(), modifiedBy: z.string().optional(), modifiedDate: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Đăng ký Official Account. Phải đính kèm giấy ủy quyền có dấu công ty; * FireAnt xác minh thủ công trước khi tài khoản được dùng. * * POST /ir/{symbol}/official-account/claim */ export const createApiIrSymbolOfficialAccountClaim = async (args: CreateApiIrSymbolOfficialAccountClaimArgs, options?: CreateApiIrSymbolOfficialAccountClaimOptions) => { const {baseUrl = "https://api.fireant.vn", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/ir/${encodeURIComponent(String(args.symbol))}/official-account/claim${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(fireAntApiModelsIRIROaAccount, await res.json()) };