import {z} from 'zod' export type QPilotCoreModelsAccessScope = 'None' | 'Merchant' | 'Site' | 'Customer' | 'Administrator' | 'All'; export type QPilotCoreModelsDtoRequestsGenerateAccessTokenDto = {accessScope: QPilotCoreModelsAccessScope, customerId?: (string | null) | undefined}; export type CreateApiSitesSiteIdAccessTokensGenerateArgs = {siteId: number, body: QPilotCoreModelsDtoRequestsGenerateAccessTokenDto}; export type CreateApiSitesSiteIdAccessTokensGenerateOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsUserRole = z.enum(["None", "Merchant", "Administrator"]); export const qPilotCoreModelsSubscriptionStatus = z.enum(["None", "Trial", "Active", "Inactive"]); export const qPilotCoreModelsSubscriptionTierType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(8), z.literal(16), z.literal(32), z.literal(64), z.literal(128), z.literal(256)]); export const qPilotCoreModelsUsersUserVerificationStatus = z.enum(["Unknown", "Verified", "Unverified", "PendingVerification"]); export const qPilotCoreModelsUsersUser = z.object({id: z.number().int().optional(), email: z.string().max(128), password: z.string().max(32), role: qPilotCoreModelsUserRole.optional(), subscriptionId: z.string().max(128).nullable().optional(), subscriptionStatus: qPilotCoreModelsSubscriptionStatus.optional(), subscriptionPaymentMethodDescription: z.string().max(128).nullable().optional(), subscriptionNextBillingDate: z.string().nullable().optional(), subscriptionUpdatedUtc: z.string().nullable().optional(), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), activeTier: qPilotCoreModelsSubscriptionTierType.optional(), chargifyProductHandle: z.string().nullable().optional(), phoneNumber: z.string().max(30).nullable().optional(), firstLogin: z.number().int().optional(), accountOwnerEmail: z.string().max(128).nullable().optional(), emailVerificationStatus: qPilotCoreModelsUsersUserVerificationStatus.optional()}); export const qPilotCoreModelsAccessScope = z.enum(["None", "Merchant", "Site", "Customer", "Administrator", "All"]); export const qPilotCoreModelsDtoEntitiesAccessTokenDto = z.object({userId: z.number().int().optional(), user: qPilotCoreModelsUsersUser.optional(), token: z.string().nullable().optional(), tokenAuth: z.string().nullable().optional(), tokenBearerAuth: z.string().nullable().optional(), accessScope: qPilotCoreModelsAccessScope.optional(), customerId: z.string().nullable().optional(), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), expiresUtc: 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 }; /** * POST /Sites/{siteId}/AccessTokens/Generate */ export const createApiSitesSiteIdAccessTokensGenerate = async (args: CreateApiSitesSiteIdAccessTokensGenerateArgs, options?: CreateApiSitesSiteIdAccessTokensGenerateOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/AccessTokens/Generate${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(qPilotCoreModelsDtoEntitiesAccessTokenDto, await res.json()) };