export type CreateApiPartnerAppArgs = {token?: string | undefined, body: {name?: string | undefined, templateMessaging?: boolean | undefined, disableOptinPrefUrl?: boolean | undefined}}; export type CreateApiPartnerAppOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * APP | Create application from Partner Portal * * POST /partner/app */ export const createApiPartnerApp = async (args: CreateApiPartnerAppArgs, options?: CreateApiPartnerAppOptions) => { const {baseUrl = "https://partner.gupshup.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (args.token != null) headers.set("token", String(args.token)) const url = `${baseUrl.replace(/\/+$/, '')}/partner/app${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };