import {z} from 'zod' export type ValidValue = {Code: string, Name: string}; export type Field = {Name: string, Description: string, Key: string, Tooltip?: string | undefined, Position: number, DefaultValue?: string | undefined, ValidValues?: Array | undefined, ValidationRegex?: string | undefined, FieldType: 'Text' | 'TextArea' | 'Integer' | 'Decimal' | 'Date' | 'DateTime' | 'Time' | 'Select' | 'Boolean' | 'ActionButton', IsFlipdishRestricted?: (boolean | null) | undefined}; export type FieldGroup = {Name: string, Description?: string | undefined, Tooltip?: string | undefined, Position: number, Fields?: Array | undefined}; export type AppStoreAppSupportInfo = {PrivacyPolicy?: string | undefined, TermsOfUse?: string | undefined, CompanyWebsite?: string | undefined, LearnMore?: string | undefined, InstallationMessage?: string | undefined, SupportEmail?: string | undefined}; export type CreateAppStoreApp = {Details: string, ConfigurationType: 'ExternalLink' | 'FlipdishHosted', StoreSelectorType: 'None' | 'Single' | 'Multiple', FieldGroups?: Array | undefined, SetupInstructions?: string | undefined, ExternalSetupLink?: string | undefined, TeammateAppAccessLevel?: ('Owner' | 'StoreOwner' | 'PropertyOwner' | 'ManagedOwner' | 'Integrator' | 'PropertyManager' | 'StoreManager' | 'StoreStaff' | 'StaffMember' | 'StoreReadOnlyAccess' | 'FinanceManger') | undefined, PermissionsType: 'Teammate', Support?: AppStoreAppSupportInfo | undefined, ExternalFunctionActionUrl?: string | undefined, ExternalFunctionSignatureKey?: string | undefined, IsPaid?: boolean | undefined, Name: string, Description: string, IsEnabled?: boolean | undefined, Categories: Array<'PointOfSale' | 'DeliveryAndLogistics' | 'CRM' | 'GiftCard' | 'Accounting' | 'LoyaltyAndMarketing' | 'Other'>, Countries: Array<'GB' | 'IE' | 'FR' | 'ES' | 'PT' | 'IT' | 'DE' | 'PL' | 'BE' | 'LU' | 'NL' | 'US' | 'CA' | 'BG' | 'MX' | 'AU' | 'NZ'>, DeveloperName?: string | undefined}; export type CreateApiApiV10OauthclientsOauthAppIdAppstoreAppsArgs = {oauthAppId: string, body: CreateAppStoreApp}; export type CreateApiApiV10OauthclientsOauthAppIdAppstoreAppsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const validValue = z.object({Code: z.string(), Name: z.string()}); export const field = z.object({Name: z.string(), Description: z.string(), Key: z.string(), Tooltip: z.string().optional(), Position: z.number().int().gte(1).lte(1000), DefaultValue: z.string().optional(), ValidValues: z.array(validValue).optional(), ValidationRegex: z.string().optional(), FieldType: z.enum(["Text", "TextArea", "Integer", "Decimal", "Date", "DateTime", "Time", "Select", "Boolean", "ActionButton"]), IsFlipdishRestricted: z.boolean().nullable().optional()}); export const fieldGroup = z.object({Name: z.string(), Description: z.string().optional(), Tooltip: z.string().optional(), Position: z.number().int().gte(1).lte(1000), Fields: z.array(field).optional()}); export const appStoreAppSupportInfo = z.object({PrivacyPolicy: z.string().optional(), TermsOfUse: z.string().optional(), CompanyWebsite: z.string().optional(), LearnMore: z.string().optional(), InstallationMessage: z.string().optional(), SupportEmail: z.string().optional()}); export const appStoreApp = z.object({Id: z.string(), VerificationStatus: z.enum(["Draft", "Submitted", "Verified"]), Logo: z.string().optional(), OAuthAppId: z.string(), Internal: z.boolean(), Details: z.string(), ConfigurationType: z.enum(["ExternalLink", "FlipdishHosted"]), StoreSelectorType: z.enum(["None", "Single", "Multiple"]), FieldGroups: z.array(fieldGroup).optional(), SetupInstructions: z.string().optional(), ExternalSetupLink: z.string().optional(), TeammateAppAccessLevel: z.enum(["Owner", "StoreOwner", "PropertyOwner", "ManagedOwner", "Integrator", "PropertyManager", "StoreManager", "StoreStaff", "StaffMember", "StoreReadOnlyAccess", "FinanceManger"]).optional(), PermissionsType: z.literal("Teammate"), Support: appStoreAppSupportInfo.optional(), ExternalFunctionActionUrl: z.string().optional(), ExternalFunctionSignatureKey: z.string().optional(), IsPaid: z.boolean().optional(), Name: z.string(), Description: z.string(), IsEnabled: z.boolean().optional(), Categories: z.array(z.enum(["PointOfSale", "DeliveryAndLogistics", "CRM", "GiftCard", "Accounting", "LoyaltyAndMarketing", "Other"])), Countries: z.array(z.enum(["GB", "IE", "FR", "ES", "PT", "IT", "DE", "PL", "BE", "LU", "NL", "US", "CA", "BG", "MX", "AU", "NZ"])), DeveloperName: z.string().optional()}); export const restApiResultAppStoreApp = z.object({Data: appStoreApp}); 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 /api/v1.0/oauthclients/{oauthAppId}/appstore/apps */ export const createApiApiV10OauthclientsOauthAppIdAppstoreApps = async (args: CreateApiApiV10OauthclientsOauthAppIdAppstoreAppsArgs, options?: CreateApiApiV10OauthclientsOauthAppIdAppstoreAppsOptions) => { const {baseUrl = "https://api.flipdish.co", 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(/\/+$/, '')}/api/v1.0/oauthclients/${encodeURIComponent(String(args.oauthAppId))}/appstore/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(restApiResultAppStoreApp, await res.json()) };