import {z} from 'zod' export type GetApiV2UserMarketplacesChannelcatalogsArgs = {storeId?: unknown | undefined}; export type GetApiV2UserMarketplacesChannelcatalogsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const beezUPCommonDocUrl = z.string(); export const beezUPCommonHref = z.string(); export const beezUPCommonOperationId = z.string(); export const beezUPCommonHttpMethod = z.enum(["GET", "POST", "PATCH", "DELETE", "PUT", "HEAD"]); export const beezUPCommonParameterIn = z.enum(["path", "header", "query", "body"]); export const beezUPCommonParameterType = z.enum(["string", "integer", "number", "boolean", "object", "array", "date", "date-time"]); export const beezUPCommonLOVLink3 = z.object({href: z.string(), method: beezUPCommonHttpMethod.optional()}); export const beezUPCommonLinkParameterProperty3 = z.object({label: z.string().optional(), value: z.object({}).optional(), required: z.boolean().optional(), type: beezUPCommonParameterType, lovLink: beezUPCommonLOVLink3.optional(), lovRequired: z.boolean().optional(), description: z.string().optional(), schema: z.string().optional()}); export const beezUPCommonLinkParameter3 = z.object({label: z.string().optional(), value: z.object({}).optional(), required: z.boolean().optional(), in: beezUPCommonParameterIn, type: beezUPCommonParameterType.optional(), lovLink: beezUPCommonLOVLink3.optional(), lovRequired: z.boolean().optional(), description: z.string().optional(), schema: z.string().optional(), properties: z.record(z.string(), beezUPCommonLinkParameterProperty3).optional()}); export const beezUPCommonSuccessSummary = z.object({successCode: z.string().optional(), successMessage: z.string().optional(), successArguments: z.record(z.string(), z.string()).optional(), propertyName: z.string().optional(), propertyValue: z.string().optional(), objectName: z.string().optional()}); export const beezUPCommonExceptionDetail = z.object({helpLink: z.string().optional(), message: z.string().optional(), stackTrace: z.string().optional(), type: z.string().optional()}); export const beezUPCommonErrorSummary = z.object({utcDate: z.string().optional(), errorGuid: z.string().optional(), errorCode: z.string().optional(), errorMessage: z.string().optional(), technicalErrorMessage: z.string().optional(), exceptionDetail: beezUPCommonExceptionDetail.optional(), errorArguments: z.record(z.string(), z.string()).optional(), propertyName: z.string().optional(), propertyValue: z.string().optional(), objectName: z.string().optional(), source: z.string().optional()}); export const beezUPCommonWarningSummary = z.object({technicalErrorMessage: z.string().optional(), warningMessage: z.string().optional(), warningCode: z.string().optional(), warningArguments: z.record(z.string(), z.string()).optional()}); export const beezUPCommonInfoSummary = z.object({informationCode: z.string().optional(), informationMessage: z.string().optional(), informationArguments: z.record(z.string(), z.string()).optional(), propertyName: z.string().optional(), propertyValue: z.string().optional(), objectName: z.string().optional()}); export const beezUPCommonInfoSummaries = z.object({successes: z.array(beezUPCommonSuccessSummary).optional(), errors: z.array(beezUPCommonErrorSummary).optional(), warnings: z.array(beezUPCommonWarningSummary).optional(), informations: z.array(beezUPCommonInfoSummary).optional()}); export const linksGetMarketplaceChannelCatalogsLink = z.object({label: z.string().optional(), docUrl: beezUPCommonDocUrl.optional(), description: z.string().optional(), href: beezUPCommonHref, operationId: beezUPCommonOperationId.optional(), method: beezUPCommonHttpMethod.optional(), parameters: z.record(z.string(), beezUPCommonLinkParameter3).optional(), urlTemplated: z.boolean().optional(), allRequiredParamsProvided: z.boolean().optional(), allOptionalParamsProvided: z.boolean().optional(), info: beezUPCommonInfoSummaries.optional()}); export const marketplaceChannelCatalogListLinks = z.object({self: linksGetMarketplaceChannelCatalogsLink}); export const beezUPCommonApiSettingsStatus = z.enum(["warning", "success", "failed"]); export const beezUPCommonMarketplaceTechnicalCode = z.string(); export const beezUPCommonMarketplaceBusinessCode = z.string(); export const beezUPCommonChannelId = z.string(); export const beezUPCommonChannelCatalogId = z.string(); export const beezUPCommonStoreId = z.string(); export const beezUPCommonMarketplaceAccountId = z.number().int(); export const marketplaceChannelCatalogLovLinks = z.object({shippingMethodLOV: beezUPCommonLOVLink3.optional(), carrierCodeLOV: beezUPCommonLOVLink3.optional(), cancelationReasonCodeLOV: beezUPCommonLOVLink3.optional(), refundReasonCodeLOV: beezUPCommonLOVLink3.optional(), marketplaceStorePropertyLOV: beezUPCommonLOVLink3.optional(), marketplaceStorePropertyGroupLOV: beezUPCommonLOVLink3.optional()}); export const linksGetChannelCatalogMarketplacePropertiesLink = z.object({label: z.string().optional(), docUrl: beezUPCommonDocUrl.optional(), description: z.string().optional(), href: beezUPCommonHref, operationId: beezUPCommonOperationId.optional(), method: beezUPCommonHttpMethod.optional(), parameters: z.record(z.string(), beezUPCommonLinkParameter3).optional(), urlTemplated: z.boolean().optional(), allRequiredParamsProvided: z.boolean().optional(), allOptionalParamsProvided: z.boolean().optional(), info: beezUPCommonInfoSummaries.optional()}); export const linksGetChannelCatalogMarketplaceSettingsLink = z.object({label: z.string().optional(), docUrl: beezUPCommonDocUrl.optional(), description: z.string().optional(), href: beezUPCommonHref, operationId: beezUPCommonOperationId.optional(), method: beezUPCommonHttpMethod.optional(), parameters: z.record(z.string(), beezUPCommonLinkParameter3).optional(), urlTemplated: z.boolean().optional(), allRequiredParamsProvided: z.boolean().optional(), allOptionalParamsProvided: z.boolean().optional(), info: beezUPCommonInfoSummaries.optional()}); export const linksGetPublicationsLink = z.object({label: z.string().optional(), docUrl: beezUPCommonDocUrl.optional(), description: z.string().optional(), href: beezUPCommonHref, operationId: beezUPCommonOperationId.optional(), method: beezUPCommonHttpMethod.optional(), parameters: z.record(z.string(), beezUPCommonLinkParameter3).optional(), urlTemplated: z.boolean().optional(), allRequiredParamsProvided: z.boolean().optional(), allOptionalParamsProvided: z.boolean().optional(), info: beezUPCommonInfoSummaries.optional()}); export const publicationStrategyKind = z.enum(["Delta", "Full", "Unpublish"]); export const feedType = z.enum(["Products", "Inventory", "Pricing", "Images", "Relationships", "Unpublish", "Offers", "OffersLT", "OffersLV", "OffersFI", "OffersEE"]); export const publicationStrategy = z.string(); export const linksPublishCatalogToMarketplaceLink = z.object({label: z.string().optional(), docUrl: beezUPCommonDocUrl.optional(), description: z.string().optional(), href: beezUPCommonHref, operationId: beezUPCommonOperationId.optional(), method: beezUPCommonHttpMethod.optional(), parameters: z.record(z.string(), beezUPCommonLinkParameter3).optional(), urlTemplated: z.boolean().optional(), allRequiredParamsProvided: z.boolean().optional(), allOptionalParamsProvided: z.boolean().optional(), info: beezUPCommonInfoSummaries.optional()}); export const marketplaceChannelCatalogPublicationOption = z.object({kind: publicationStrategyKind, feedType: feedType, withUnpublish: z.boolean(), strategy: publicationStrategy, link: linksPublishCatalogToMarketplaceLink}); export const marketplaceChannelCatalogLinks = z.object({properties: linksGetChannelCatalogMarketplacePropertiesLink, settings: linksGetChannelCatalogMarketplaceSettingsLink, publications: linksGetPublicationsLink.optional(), publishOptions: z.array(marketplaceChannelCatalogPublicationOption).optional()}); export const marketplaceChannelCatalog = z.object({apiSettingsStatus: beezUPCommonApiSettingsStatus, enabled: z.boolean(), marketplaceTechnicalCode: beezUPCommonMarketplaceTechnicalCode, marketplaceBusinessCode: beezUPCommonMarketplaceBusinessCode, marketplaceMarketPlaceId: z.string(), marketplaceIsoCountryCodeAlpha2: z.string(), beezUPMarketplaceName: z.string(), beezUPChannelId: beezUPCommonChannelId, beezUPChannelCatalogId: beezUPCommonChannelCatalogId, beezUPStoreId: beezUPCommonStoreId, beezUPStoreName: z.string(), marketplaceMerchantIdentifiers: z.record(z.string(), z.string()).optional(), marketplaceAccountId: beezUPCommonMarketplaceAccountId.optional(), lovLinks: marketplaceChannelCatalogLovLinks, links: marketplaceChannelCatalogLinks, isChannelV2: z.boolean().optional()}); export const marketplaceChannelCatalogList = z.object({links: marketplaceChannelCatalogListLinks, marketplaceChannelCatalogs: z.array(marketplaceChannelCatalog)}); 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 your marketplace channel catalog list * * GET /v2/user/marketplaces/channelcatalogs/ */ export const getApiV2UserMarketplacesChannelcatalogs = async (args: GetApiV2UserMarketplacesChannelcatalogsArgs, options?: GetApiV2UserMarketplacesChannelcatalogsOptions) => { const {baseUrl = "https://api.beezup.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.storeId != null) query.append("storeId", String(args.storeId)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/user/marketplaces/channelcatalogs/${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(marketplaceChannelCatalogList, await res.json()) };