import {z} from 'zod' export type GetApiV2UserCustomerStoresArgs = {'If-None-Match'?: string | undefined}; export type GetApiV2UserCustomerStoresOptions = {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 linksGetStoresLink = 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 linksCreateStoreLink = 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 storeListLinks = z.object({self: linksGetStoresLink.optional(), createStore: linksCreateStoreLink.optional()}); export const beezUPCommonStoreId = z.string(); export const storeName = z.string(); export const storeUrl = z.string(); export const storeCountryIsoCodeAlpha3 = z.string(); export const beezUPCommonCurrencyCode = z.string(); export const storeSector = z.string(); export const storeSectors = z.array(storeSector); export const storeUserRole = z.enum(["Owner", "User"]); export const storeStatus = z.enum(["Active", "SystemBlocked", "UserBlocked"]); export const offerId = z.number().int().gte(1); export const linksGetStoreLink = 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 linksDeleteStoreLink = 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 linksUpdateStoreLink = 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 linksGetStoreSharesLink = 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 linksShareStoreLink = 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 storeLinks = z.object({self: linksGetStoreLink.optional(), deleteStore: linksDeleteStoreLink.optional(), updateStore: linksUpdateStoreLink.optional(), shares: linksGetStoreSharesLink.optional(), share: linksShareStoreLink.optional()}); export const store = z.object({storeId: beezUPCommonStoreId, name: storeName, url: storeUrl, countryIsoCodeAlpha3: storeCountryIsoCodeAlpha3, currencyCode: beezUPCommonCurrencyCode, sectors: storeSectors, userRole: storeUserRole, status: storeStatus, ownerUserId: z.string(), offerId: offerId, offerName: z.string(), shareCount: z.number().int(), creationUtcDate: z.string(), goVersion: z.number().int(), links: storeLinks, isTest: z.boolean()}); export const storeList = z.object({links: storeListLinks, stores: z.array(store)}); 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 store list * * GET /v2/user/customer/stores */ export const getApiV2UserCustomerStores = async (args: GetApiV2UserCustomerStoresArgs, options?: GetApiV2UserCustomerStoresOptions) => { 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['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/v2/user/customer/stores${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(storeList, await res.json()) };