import {z} from 'zod' export type UpdateStoreForm = {name: string, description: string, prependProductNameToReceipt: boolean, currencyCode: string, isAutomaticReviewsEnabled: boolean, termsOfServiceUrl?: (string | null) | undefined, refundPolicyUrl?: (string | null) | undefined, privacyPolicyUrl?: (string | null) | undefined, isTicketingEnabled: boolean, externalSupportUrl?: (string | null) | undefined, externalSupportDescription?: (string | null) | undefined, showPublicStats: boolean, showRecentOrderToasts: boolean, enableCartRecovery: boolean}; export type UpdateApiStoresStoreIdArgs = {storeId: string, body: UpdateStoreForm}; export type UpdateApiStoresStoreIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const builderWebsite = z.object({id: z.string(), dateCreated: z.string(), storageKey: z.string().max(512).nullable().optional(), fileDataHash: z.string().max(128), compressedSize: z.number().int(), size: z.number().int(), projectId: z.string(), userId: z.string().min(1).max(36), storeId: z.string(), sourceTemplateId: z.string().nullable().optional(), sourceCommitHash: z.string().max(40).nullable().optional(), sourceReleaseTag: z.string().max(50).nullable().optional()}); export const builderWebsiteBackup = z.object({id: z.string(), dateCreated: z.string(), storageKey: z.string().max(512).nullable().optional(), fileDataHash: z.string().max(128), compressedSize: z.number().int(), size: z.number().int(), projectId: z.string(), websiteId: z.string(), name: z.string().max(128).nullable().optional(), userId: z.string().min(1).max(36), storeId: z.string()}); export const builderPreviewEvent = z.object({id: z.string(), dateCreated: z.string(), source: z.string().max(128), type: z.string().max(128), message: z.string().max(5000), machineId: z.string()}); export const builderPreviewMachine = z.object({id: z.string(), dateCreated: z.string(), isTerminated: z.boolean(), source: z.string().min(1).max(128), sourceId: z.string().min(1).max(128), name: z.string().min(1).max(128), privateIpAddress: z.string().min(1).max(45), events: z.array(builderPreviewEvent), storeId: z.string(), projectId: z.string(), userId: z.string().min(1).max(48)}); export const builderGlobalSeo = z.object({id: z.string(), dateCreated: z.string(), title: z.string().max(128).nullable().optional(), description: z.string().max(500).nullable().optional(), ogImage: z.string().max(512).nullable().optional(), projectId: z.string(), project: z.lazy(() => builderProject)}); export const builderPage = z.object({id: z.string(), dateCreated: z.string(), title: z.string().max(128).nullable().optional(), description: z.string().max(500).nullable().optional(), ogImage: z.string().max(512).nullable().optional(), projectId: z.string(), project: z.lazy(() => builderProject), path: z.string().min(1).max(256)}); export const builderProject: z.ZodType = z.object({id: z.string(), dateCreated: z.string(), urlId: z.string().max(128).nullable().optional(), name: z.string().max(128).nullable().optional(), currentWebsiteId: z.string().nullable().optional(), currentWebsite: builderWebsite.optional(), userId: z.string().min(1).max(36), storeId: z.string(), backups: z.array(builderWebsiteBackup), machines: z.array(builderPreviewMachine), globalSeo: builderGlobalSeo.optional(), pages: z.array(builderPage), environmentVariables: z.record(z.string(), z.string())}); export const storedFile = z.object({id: z.string(), dateCreated: z.string(), friendlyName: z.string().min(1).max(128), ipAddress: z.string().min(1).max(45), userId: z.string().min(1).max(36)}); export const stockCalculationMode = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const customFieldOption = z.object({id: z.string(), dateCreated: z.string(), customFieldId: z.string(), label: z.string().max(128), value: z.string().max(64), order: z.number().int().gte(0).lte(2147483647)}); export const customField = z.object({id: z.string(), dateCreated: z.string(), variantId: z.string(), label: z.string().min(1).max(128), identifier: z.string().min(1).max(64), placeholder: z.string().max(256).nullable().optional(), type: z.string().min(1).max(256), isRequired: z.boolean(), hint: z.string().max(512).nullable().optional(), options: z.array(customFieldOption)}); export const volumeDiscountType = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const volumeDiscount = z.object({id: z.string(), dateCreated: z.string(), variantId: z.string(), quantity: z.number().int().gte(1).lte(2147483647), discountType: volumeDiscountType, discountValue: z.number().gte(0).lte(100000)}); export const billingInterval = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const variant = z.object({id: z.string(), dateCreated: z.string(), name: z.string().min(3).max(128), productId: z.string(), storeId: z.string(), cost: z.number().gte(0).lte(100000), deliveryTypes: z.array(z.string()), files: z.array(storedFile), dynamicUrl: z.string().max(2048).nullable().optional(), deliveryMessage: z.string().max(4096).nullable().optional(), minimumQuantity: z.number().int(), maximumQuantity: z.number().int(), order: z.number().int(), imageNames: z.array(z.string()), stock: z.number().int(), stockMode: stockCalculationMode, customFields: z.array(customField), volumeDiscounts: z.array(volumeDiscount), disableVolumeDiscountOnCoupon: z.boolean(), metadata: z.string().max(1000).nullable().optional(), billingInterval: billingInterval.optional(), customIntervalDays: z.number().int().nullable().optional()}); export const privacy = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]); export const affiliateDiscountOverride = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const subscriptionCancelMode = z.union([z.literal(0), z.literal(1)]); export const product = z.object({id: z.string(), dateCreated: z.string(), variants: z.array(variant), name: z.string().min(3).max(128), slug: z.string().min(1).max(72).nullable().optional(), description: z.string().min(1).max(16384), metaDescription: z.string().max(500).nullable().optional(), visibility: privacy, imageNames: z.array(z.string()), storeId: z.string(), userId: z.string().min(1).max(36), shouldBlockVpns: z.boolean(), order: z.number().int(), isBestSeller: z.boolean(), blacklistedPaymentGateways: z.array(z.string()), additionalFees: z.record(z.string(), z.string()), additionalFixedFees: z.record(z.string(), z.string()), metadata: z.string().max(10000).nullable().optional(), affiliateDiscountMode: affiliateDiscountOverride, customAffiliateDiscountPercentage: z.number().int().gte(0).lte(100).nullable().optional(), subscriptionAllowPause: z.boolean().nullable().optional(), subscriptionMaxPauseDurationDays: z.number().int().nullable().optional(), subscriptionMaxPauseCount: z.number().int().nullable().optional(), subscriptionAllowCancel: z.boolean().nullable().optional(), subscriptionCancelMode: subscriptionCancelMode.optional(), subscriptionAllowReactivate: z.boolean().nullable().optional(), subscriptionGracePeriodDays: z.number().int().nullable().optional(), subscriptionRevokeOnExpiry: z.boolean().nullable().optional()}); export const categoryProduct = z.object({id: z.string(), dateCreated: z.string(), categoryId: z.string(), category: z.lazy(() => category), productId: z.string(), product: product, order: z.number().int()}); export const category: z.ZodType = z.object({id: z.string(), dateCreated: z.string(), name: z.string().min(3).max(128), visibility: privacy, slug: z.string().min(1).max(72).nullable().optional(), metaDescription: z.string().max(500).nullable().optional(), imageName: z.string().max(128).nullable().optional(), order: z.number().int(), storeId: z.string(), products: z.array(categoryProduct)}); export const blogCategory = z.object({id: z.string(), dateCreated: z.string(), name: z.string().min(3).max(128), slug: z.string().min(1).max(72).nullable().optional(), description: z.string().max(500).nullable().optional(), visibility: privacy, order: z.number().int(), storeId: z.string(), posts: z.array(z.lazy(() => blogPostCategory))}); export const blogPostCategory: z.ZodType = z.object({id: z.string(), dateCreated: z.string(), blogPostId: z.string(), post: z.lazy(() => blogPost), blogCategoryId: z.string(), category: blogCategory, order: z.number().int()}); export const blogPost: z.ZodType = z.object({id: z.string(), dateCreated: z.string(), title: z.string().min(3).max(256), slug: z.string().min(1).max(72).nullable().optional(), excerpt: z.string().max(500).nullable().optional(), content: z.string().min(1).max(100000), metaDescription: z.string().max(500).nullable().optional(), coverImageName: z.string().max(128).nullable().optional(), visibility: privacy, isFeatured: z.boolean(), publishedAt: z.string().nullable().optional(), tags: z.array(z.string()), order: z.number().int(), readTimeMinutes: z.number().int(), storeId: z.string(), authorId: z.string().min(1).max(36), categories: z.array(blogPostCategory)}); export const affiliateOptions = z.object({id: z.string(), dateCreated: z.string(), isEnabled: z.boolean(), defaultReturnPercentage: z.number().int(), defaultPercentageOff: z.number().int().nullable().optional(), isPublicRegistrationEnabled: z.boolean(), isLinkEditingEnabled: z.boolean(), canConvertAffiliateBalance: z.boolean()}); export const storeBrandOptions = z.object({id: z.string(), dateCreated: z.string(), storeId: z.string(), bannerFileName: z.string().max(64).nullable().optional(), iconFileName: z.string().max(64).nullable().optional(), accentColor: z.string().max(9).nullable().optional(), isAutomaticCurrencyConversionEnabled: z.boolean()}); export const notificationOptions = z.object({id: z.string(), dateCreated: z.string(), discordWebhookUrl: z.string().max(512).nullable().optional(), disabledEmailNotifications: z.array(z.string()), disabledDiscordNotifications: z.array(z.string())}); export const storeBusinessInformation = z.object({legalEntityType: z.string().min(1).max(1000).nullable().optional(), taxId: z.string().max(50).nullable().optional(), fullName: z.string().max(100).nullable().optional(), addressLine1: z.string().max(200).nullable().optional(), addressLine2: z.string().max(200).nullable().optional(), city: z.string().max(100).nullable().optional(), region: z.string().max(100).nullable().optional(), postalCode: z.string().max(20).nullable().optional(), countryCode: z.string().min(1).max(2), id: z.string(), dateCreated: z.string()}); export const taxOptions = z.object({id: z.string(), dateCreated: z.string(), isEnabled: z.boolean(), taxBehavior: z.string().max(16), businessCountryCode: z.string().max(2).nullable().optional(), vatId: z.string().max(64).nullable().optional(), defaultTaxRate: z.number(), defaultTaxName: z.string().max(64)}); export const storeSubscriptionOptions = z.object({id: z.string(), dateCreated: z.string(), allowPause: z.boolean(), maxPauseDurationDays: z.number().int().nullable().optional(), maxPauseCount: z.number().int().nullable().optional(), allowCancel: z.boolean(), cancelMode: subscriptionCancelMode, allowReactivate: z.boolean(), allowPaymentMethodUpdate: z.boolean(), gracePeriodDays: z.number().int(), maxRetryAttempts: z.number().int(), reminderSchedule: z.string().max(64), sendExpiryNotifications: z.boolean(), revokeOnExpiry: z.boolean(), forceManualRenewal: z.boolean(), storeId: z.string()}); export const coupon = z.object({id: z.string(), dateCreated: z.string(), code: z.string().min(3).max(32), uses: z.number().int(), maximumUses: z.number().int().gte(-1).lte(100000000), percentageDecrease: z.number().gte(0).lte(100).nullable().optional(), amountDecrease: z.number().gte(0).lte(100000).nullable().optional(), isEnabled: z.boolean(), variantIds: z.array(z.string()).nullable().optional(), expirationDate: z.string().nullable().optional(), storeId: z.string()}); export const blacklistType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7)]); export const blacklist = z.object({id: z.string(), dateCreated: z.string(), type: blacklistType, data: z.string().min(1).max(8000), note: z.string().max(2000).nullable().optional(), isEnabled: z.boolean(), storeId: z.string()}); export const store = z.object({id: z.string(), dateCreated: z.string(), builderProjects: z.array(builderProject), name: z.string().min(3).max(64), description: z.string().max(4096), url: z.string().min(3).max(64), urlHistory: z.array(z.string()), domain: z.string().min(1).max(72), customDomain: z.string().max(128).nullable().optional(), lastCustomDomainUpdate: z.string(), products: z.array(product), categories: z.array(category), blogPosts: z.array(blogPost), blogCategories: z.array(blogCategory), userId: z.string().min(1).max(36), affiliateOptions: affiliateOptions.optional(), storeBrandOptions: storeBrandOptions.optional(), notificationOptions: notificationOptions.optional(), businessInformation: storeBusinessInformation.optional(), taxOptions: taxOptions.optional(), subscriptionOptions: storeSubscriptionOptions.optional(), coupons: z.array(coupon), blacklists: z.array(blacklist), webhookSecret: z.string().max(128), currencyCode: z.string().max(4), prependProductNameToReceipt: z.boolean(), isAutomaticReviewsEnabled: z.boolean(), maintenanceReason: z.string().max(1024).nullable().optional(), isCustomerBalanceEnabled: z.boolean(), termsOfServiceUrl: z.string().max(512).nullable().optional(), refundPolicyUrl: z.string().max(512).nullable().optional(), privacyPolicyUrl: z.string().max(512).nullable().optional(), isTicketingEnabled: z.boolean(), externalSupportUrl: z.string().max(512).nullable().optional(), externalSupportDescription: z.string().max(1024).nullable().optional(), autoBlockOnChargeback: z.boolean(), blockVpnProxy: z.boolean(), kickFromDiscordOnBlock: z.boolean(), isInactive: z.boolean(), showPublicStats: z.boolean(), showRecentOrderToasts: z.boolean(), enableCartRecovery: z.boolean()}); export const storeResponse = z.object({success: z.boolean(), message: z.string().nullable().optional(), code: z.string().nullable().optional(), data: store.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 }; /** * Update a store * * PUT /stores/{storeId} */ export const updateApiStoresStoreId = async (args: UpdateApiStoresStoreIdArgs, options?: UpdateApiStoresStoreIdOptions) => { const {baseUrl = "https://api.komerza.com", 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 ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/stores/${encodeURIComponent(String(args.storeId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(storeResponse, await res.json()) };