import {z} from 'zod' export type DT013EnvironmentTag = 'PRD' | 'SITB' | 'SIT' | 'UIT' | 'DEV'; export type DT020NSubText = string | null; export type DT995SenderUniqueReference = string; export type DT003DateTime = string; export type DT006DIPParticipantID = string; export type DT009DIPParticipantRole = string; export type DT011NCorrelationID = string | null; export type DT006NDIPParticipantID = string | null; export type S1 = {environmentTag: DT013EnvironmentTag, subText: DT020NSubText, senderUniqueReference: DT995SenderUniqueReference, senderTimestamp: DT003DateTime, senderDIPID: DT006DIPParticipantID, senderRoleID: DT009DIPParticipantRole, senderCorrelationID: DT011NCorrelationID, DIPConnectionProviderID: DT006NDIPParticipantID}; export type A0 = {primaryRecipients: Array, secondaryRecipients: Array, always: Array}; export type DT014DIPTransactionID = string; export type DI986PublicationID = string; export type DI988ReplayIndicator = boolean; export type DT018NURL = string | null; export type D0 = {transactionID: DT014DIPTransactionID, transactionTimestamp: DT003DateTime, publicationID: DI986PublicationID, initialCorrelationID: DT011NCorrelationID, replayIndicator: DI988ReplayIndicator, serviceTicketURL: DT018NURL}; export type DT002MPAN = string; export type DI037GSPGroupID = '_A' | '_B' | '_C' | '_D' | '_E' | '_F' | '_G' | '_H' | '_J' | '_K' | '_L' | '_M' | '_N' | '_P'; export type M0 = {MPANCore: DT002MPAN, distributorDIPID: DT006DIPParticipantID, GSPGroupID: DI037GSPGroupID}; export type DI849CSSRegistrationID = string; export type B013 = {CSSRegistrationID: DI849CSSRegistrationID}; export type DT027MPID = string; export type B002 = {incomingSupplierDIPID: DT006DIPParticipantID, incomingSupplierMPID: DT027MPID, supplierEffectiveFromDate: DT003DateTime}; export type B003 = {outgoingSupplierDIPID: DT006DIPParticipantID, outgoingSupplierMPID: DT027MPID, supplierEffectiveToDate: DT003DateTime}; export type DI030DomesticPremiseIndicator = boolean; export type B004 = {domesticPremiseIndicator: DI030DomesticPremiseIndicator, domesticPremiseIndicatorEffectiveFromDate: DT003DateTime}; export type DT027NMPID = string | null; export type B005 = {currentMeteringServiceDIPID: DT006NDIPParticipantID, currentMeteringServiceMPID: DT027NMPID, currentDataServiceDIPID: DT006NDIPParticipantID, currentDataServiceMPID: DT027NMPID}; export type DI021CustomerDirectContractMeteringService = boolean; export type DI022CustomerDirectContractDataService = boolean; export type B006 = {customerDirectContractMeteringService: DI021CustomerDirectContractMeteringService, customerDirectContractMeteringServiceDIPID: DT006NDIPParticipantID, customerDirectContractDataService: DI022CustomerDirectContractDataService, customerDirectContractDataServiceDIPID: DT006NDIPParticipantID}; export type DT007NUKPostCode = string | null; export type DT001NAddressLine = string | null; export type B022 = {meteringPointPostcode: DT007NUKPostCode, addressLine1: DT001NAddressLine, addressLine2: DT001NAddressLine, addressLine3: DT001NAddressLine, addressLine4: DT001NAddressLine, addressLine5: DT001NAddressLine, addressLine6: DT001NAddressLine, addressLine7: DT001NAddressLine, addressLine8: DT001NAddressLine, addressLine9: DT001NAddressLine}; export type DI015ConnectionTypeIndicator = 'W' | 'L' | 'H' | 'E' | 'U'; export type DI035EnergyDirection = 'I' | 'E'; export type DI127MeteredIndicator = boolean; export type B023 = {connectionTypeIndicator: DI015ConnectionTypeIndicator, connectionTypeEffectiveFromDate: DT003DateTime, energyDirection: DI035EnergyDirection, meteredIndicator: DI127MeteredIndicator}; export type DI128DUOSTariffID = string; export type B024 = {DUOSTariffID: DI128DUOSTariffID, DUOSTariffIDEffectiveFromDate: DT003DateTime}; export type DI033EnergisationStatus = 'D' | 'E' | 'U'; export type B025 = {energisationStatus: DI033EnergisationStatus, energisationStatusEffectiveFromDate: DT003DateTime}; export type DI050MarketSegmentIndicator = 'U' | 'S' | 'A'; export type B026 = {marketSegmentIndicator: DI050MarketSegmentIndicator, marketSegmentIndicatorEffectiveFromDate: DT003DateTime}; export type DT016Decimal93 = string; export type DI150AnnualConsumptionQualityIndicator = 'A' | '1' | '2' | '3' | '4' | '5' | 'D'; export type B027 = {annualConsumption: DT016Decimal93, annualConsumptionEffectiveFromDate: DT003DateTime, annualConsumptionQualityIndicator: DI150AnnualConsumptionQualityIndicator}; export type DI025DCCServiceFlag = 'A' | 'I' | 'N'; export type B029 = {DCCServiceFlag: DI025DCCServiceFlag, DCCEffectiveFromDate: DT003DateTime}; export type DI137IHDInstallStatus = 'I' | 'D' | 'E' | 'F' | null; export type B030 = {IHDInstallStatus: DI137IHDInstallStatus, IHDEffectiveFromDate: DT003DateTime}; export type DI134SMSO = string | null; export type B031 = {SMSOID: DI134SMSO, SMSOEffectiveFromDate: DT003DateTime}; export type DI122ProfileClass = string | null; export type DT003NDateTime = string | null; export type DI123SSC = string | null; export type B032 = {profileClass: DI122ProfileClass, profileClassEffectiveFromDate: DT003NDateTime, SSC: DI123SSC, SSCEffectiveFromDate: DT003NDateTime}; export type DI151LinkedMPANEnergyDirection = 'I' | 'E'; export type B035 = {linkedImportExportMPAN: DT002MPAN, linkedMPANEnergyDirection: DI151LinkedMPANEnergyDirection, importExportMPANSupplierDIPID: DT006NDIPParticipantID, importExportMPANSupplierMPID: DT027NMPID}; export type DT002NMPAN = string | null; export type B037 = {primaryMPAN: DT002NMPAN, secondaryMPAN: DT002NMPAN}; export type IF001ChangeOfSupplier = {CommonBlock: {S0: {interfaceID: 'IF-001', schemaVersion: '011', eventCode: '[ChangeOfSupplier]'}, S1: S1, A0?: A0 | undefined, D0?: D0 | undefined, M0: M0}, CustomBlock: {B013: B013, B002: B002, B003: B003, B004: B004, B005?: B005 | undefined, B006?: B006 | undefined, B022: B022, B023: B023, B024: B024, B025: B025, B026: B026, B027?: B027 | undefined, B029?: B029 | undefined, B030?: B030 | undefined, B031?: B031 | undefined, B032?: B032 | undefined, B035List?: Array | undefined, B037List?: Array | undefined}}; export type CreateApiValidateIF001ChangeOfSupplierArgs = {body: Array<{payload?: IF001ChangeOfSupplier | undefined}>}; export type CreateApiValidateIF001ChangeOfSupplierOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiValidateIF001ChangeOfSupplierResponse = 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 }; /** * Submit IF-001 with Event Code ChangeOfSupplier message for validation * * POST /validate/IF-001/ChangeOfSupplier */ export const createApiValidateIF001ChangeOfSupplier = async (args: CreateApiValidateIF001ChangeOfSupplierArgs, options?: CreateApiValidateIF001ChangeOfSupplierOptions) => { const {baseUrl = "https://dip-api-documentation.elexon.co.uk", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/validate/IF-001/ChangeOfSupplier${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(createApiValidateIF001ChangeOfSupplierResponse, await res.json()) };