import {z} from 'zod' export type GetApiV1AppsAppIdLayoutsArgs = {appId: number, published: boolean}; export type GetApiV1AppsAppIdLayoutsOptions = {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 clientUserClientsEntity = z.object({mappingId: z.number(), role: z.object({}), clientUser: z.lazy(() => clientUserEntity), client: z.lazy(() => clientEntity)}); export const clientUserEntity: z.ZodType = z.object({id: z.number(), firstName: z.string(), lastName: z.string(), address: z.string(), profilePicture: z.string(), email: z.string(), password: z.string(), address2: z.string(), city: z.string(), postcode: z.string(), country: z.string(), state: z.string(), cc: z.number(), phone: z.string(), activationHash: z.string(), activationEmailResentAt: z.string(), passwordLockedAt: z.string(), accountStatus: z.object({}), emailVerified: z.boolean(), timezone: z.string(), registeredIp: z.string(), createdAt: z.string(), updatedAt: z.string(), aid: z.string(), emailList: z.object({}), onboardingCompleted: z.number(), lastCheckedForInactivity: z.string(), receiveNewsletters: z.number(), lastLogin: z.string(), gitHubId: z.number(), googleId: z.number(), clients: z.array(z.lazy(() => clientEntity)), clientUserClients: z.array(clientUserClientsEntity), source: z.string().optional(), isTwoFactorEnabled: z.number(), twoFactorSecret: z.string().optional(), passwordResetRequestedAt: z.string()}); export const clientEntity: z.ZodType = z.object({id: z.number(), name: z.string(), createdAt: z.string(), updatedAt: z.string(), stripeId: z.string(), stripePaymentId: z.string(), defaultApp: z.number(), clientUsers: z.array(clientUserEntity), clientUserClients: z.array(clientUserClientsEntity), licenseKey: z.string().optional(), licensePublicKey: z.string().optional(), licenseAuthToken: z.string().optional(), status: z.enum(["active", "send_suspended", "suspended"]), version: z.string().optional(), region: z.string().optional()}); export const layoutEntity = z.object({id: z.number(), appId: z.number(), identifier: z.string(), name: z.string(), clientUserId: z.number().optional(), clientId: z.number().optional(), jsonSpec: z.object({}), publishedJsonSpec: z.object({}), hasUnpublishedChanges: z.boolean(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string(), isDefault: z.boolean(), app: appEntity, client: clientEntity, clientUser: clientUserEntity}); export const getApiV1AppsAppIdLayoutsResponse = z.array(layoutEntity); 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 }; /** * GET /v1/apps/{appId}/layouts */ export const getApiV1AppsAppIdLayouts = async (args: GetApiV1AppsAppIdLayoutsArgs, options: GetApiV1AppsAppIdLayoutsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.published != null) query.append("published", String(args.published)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/apps/${encodeURIComponent(String(args.appId))}/layouts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1AppsAppIdLayoutsResponse, await res.json()) };