import {z} from 'zod' export type SitesUpsertIndustryDefinitionPayload = {industry: string, industryStandard: string}; export type SitesUpsertYourReference = {id: string, source?: (string | null) | undefined}; export type SitesUpsertSiteType = 'Supplier' | 'Customer' | 'Own'; export type PublicLevel = 'NA' | 'No' | 'Low' | 'Mid' | 'High' | 'Critical'; export type Priority = 'Low' | 'Mid' | 'High' | 'Critical'; export type SitesUpsertExternalReferencePayload = {externalId: string, system: string}; export type SitesUpsertImpactDataPayload = {year: number, bi12MlnEuro?: (number | null) | undefined, grossMttrEMonths?: (number | null) | undefined, grossMttrIMonths?: (number | null) | undefined, cocSigned?: (boolean | null) | undefined, additionalInformation?: (string | null) | undefined}; export type BirsLocation = 'SameBuilding' | 'DifferentFireSection' | 'DifferentBuilding' | 'NotApplicable'; export type BirsDeviation = 'NotApplicable' | 'OnTarget' | 'Below' | 'Above'; export type SitesUpsertSafetyStockPayload = {onPremiseStockLevelMonths?: (number | null) | undefined, atSupplierLocation?: (BirsLocation | null) | undefined, atSupplierDeviation?: (BirsDeviation | null) | undefined, atSupplierStockLevelMonths?: (number | null) | undefined, atSupplierLastConfirmedDate?: (string | null) | undefined, inLogisticChainDaysOnHand?: (number | null) | undefined}; export type SitesUpsertPayloadSiteEntry = {name: string, countryCode: string, locality: string, addressLine: string, postalCode?: (string | null) | undefined, industries?: (Array | null) | undefined, website?: (string | null) | undefined, contact?: (Array | null) | undefined, yourReference: SitesUpsertYourReference, additionalReferences?: Array | undefined, connectionType?: SitesUpsertSiteType | undefined, diImpact?: (PublicLevel | null) | undefined, biImpact?: (PublicLevel | null) | undefined, priority?: (Priority | null) | undefined, spendData?: (number | null) | undefined, collectionNames?: (Array | null) | undefined, externalReferences?: (Array | null) | undefined, postInitScreeningPeriod?: (number | null) | undefined, impactData?: (SitesUpsertImpactDataPayload | null) | undefined, safetyStock?: (SitesUpsertSafetyStockPayload | null) | undefined}; export type PublicFullSitesUpsertPayload = {siteData: Array, dryRun: boolean}; export type CreateApiPublicV1SitesUpsertFullArgs = {body: PublicFullSitesUpsertPayload}; export type CreateApiPublicV1SitesUpsertFullOptions = {baseUrl?: string | undefined, TokenAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const sitesUpsertRequestCreatedResponse = z.object({requestId: z.string()}); 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 }; /** * Upsert suppliers and their desired collections with a full load. * * POST /public/v1/sites-upsert/full */ export const createApiPublicV1SitesUpsertFull = async (args: CreateApiPublicV1SitesUpsertFullArgs, options?: CreateApiPublicV1SitesUpsertFullOptions) => { const {baseUrl = "https://api.prewave.com", fetch: fetchFn = fetch, TokenAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (TokenAuthentication !== undefined) headers.set("X-Auth-Token", TokenAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/sites-upsert/full${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(sitesUpsertRequestCreatedResponse, await res.json()) };