import {z} from 'zod' export type CreateAppDTO = {name: string}; export type CreateApiV1ClientsClientIdAppsArgs = {body: CreateAppDTO}; export type CreateApiV1ClientsClientIdAppsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const providerConfigOptionEntity = z.object({id: z.number(), provider: z.lazy(() => providerEntity), config: z.string(), required: z.boolean(), description: z.string()}); export const providerEntity: z.ZodType = z.object({identifier: z.object({}), name: z.string(), description: z.string().nullable(), integrationMessage: z.string(), icon: z.string().nullable(), channel: z.object({}), configOptions: z.array(providerConfigOptionEntity), isActive: z.boolean(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const appChannelProviderConfigEntity = z.object({id: z.number(), appChannelProvider: z.lazy(() => appChannelProviderEntity), config: z.string(), value: z.string(), isEncrypted: z.boolean(), appChannelProviderId: z.number().optional()}); export const appChannelProviderEntity: z.ZodType = z.object({id: z.number(), app: z.lazy(() => appEntity), channel: z.object({}), provider: providerEntity, configs: z.array(appChannelProviderConfigEntity), enabled: z.boolean(), deliveryOrder: z.number(), selectionCondition: z.string().nullable().optional(), notificationCount: z.number().optional(), instanceName: z.string().nullable().optional()}); export const appEntity: z.ZodType = z.object({id: z.number(), clientId: z.number(), apiKey: z.string(), notificationEnabled: z.boolean(), name: z.string(), url: z.string(), channelProviders: z.array(appChannelProviderEntity), type: z.object({}), subdomain: z.string().nullable(), apiSecret: z.string(), gcmKey: z.string().nullable(), senderId: z.string().nullable(), domain: z.string().nullable(), welcomeMessage: z.string(), customEvents: z.string().nullable(), optInType: z.object({}), prePrompt: z.number(), serviceWorkerPath: z.string().nullable(), xPos: z.number(), yPos: z.number(), defaultPosition: z.string(), posTop: z.number().nullable(), posBottom: z.number().nullable(), posLeft: z.number().nullable(), posRight: z.number().nullable(), promptDelay: z.number(), bgcolor: z.string().nullable(), fcolor: z.string().nullable(), confirmationButtonText: z.string(), declineButtonText: z.string(), lastCheckedForCodeIntegration: z.string(), disableUserActivityTrackingByDefault: z.number(), disableLocationIpTracking: z.number(), websiteType: z.object({}), siteOnboardingCompleted: z.number(), panelUiStyle: z.string(), widgetType: z.string().nullable(), bellIconDivId: z.string().nullable(), websiteIcon: z.string().nullable(), onBoardingStepsCompleted: z.object({}).nullable(), playSound: z.number(), vapidPrivateKey: z.string(), vapidPublicKey: z.string(), hideBranding: z.boolean(), enableUserSignatureVerification: z.boolean(), enableWebPush: z.boolean(), rsaPublicKey: z.string().nullable(), rtmProvider: z.object({}), secureAuth: z.boolean(), deletedAt: z.string().optional(), inAppCodeIntegration: z.boolean(), webPushCodeIntegration: z.boolean(), isDefault: z.boolean().optional(), isProduction: z.boolean().optional(), order: z.number().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 }; /** * POST /v1/clients/{clientId}/apps */ export const createApiV1ClientsClientIdApps = async (args: CreateApiV1ClientsClientIdAppsArgs, options: CreateApiV1ClientsClientIdAppsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/clients/${encodeURIComponent(String(args.clientId))}/apps${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(appEntity, await res.json()) };