import {z} from 'zod' export type ComMtnAggregatorModelsRequestInteractionDate = {startDateTime?: string | undefined}; export type ComMtnAggregatorModelsRequestExternalIdentifier = {id?: string | undefined, owner?: string | undefined, externalIdentifierType?: string | undefined}; export type ComMtnAggregatorModelsRequestRelatedParty = {role?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined, name?: string | undefined, engagedParty?: ({id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}) | undefined, partyOrPartyRole?: ({id?: string | undefined, name?: string | undefined, '@type'?: string | undefined, '@referredType'?: string | undefined, href?: string | undefined}) | undefined}; export type ComMtnAggregatorModelsRequestExternalSystem = {id?: string | undefined, system?: string | undefined, '@type'?: string | undefined, '@baseType'?: string | undefined}; export type ComMtnAggregatorModelsRequestCustomFields = {productOrderGroup?: Array | undefined, registrationType?: string | undefined}; export type ComMtnAggregatorModelsRequestProductOffering = {id?: string | undefined, href?: string | undefined, externalSystem?: Array | undefined, name?: string | undefined, category?: (Array<{name?: string | undefined, version?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}>) | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined}; export type ComMtnAggregatorModelsRequestChannel = {name?: string | undefined, role?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}; export type ComMtnAggregatorModelsRequestProduct = {id?: string | undefined, href?: string | undefined, customFields?: ComMtnAggregatorModelsRequestCustomFields | undefined, externalSystem?: Array | undefined, name?: string | undefined, startDate?: string | undefined, status?: string | undefined, createdDate?: string | undefined, modifiedDate?: string | undefined, businessType?: string | undefined, technology?: string | undefined, publicIdentifier?: string | undefined, productSpecification?: ({id?: string | undefined, '@referredType'?: string | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined, name?: string | undefined, version?: string | undefined, technology?: Array | undefined, LoB?: string | undefined}) | undefined, productOffering?: ComMtnAggregatorModelsRequestProductOffering | undefined, productOrder?: (Array<{orderItemId?: string | undefined, orderItemAction?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}>) | undefined, channel?: Array | undefined, relatedParty?: Array | undefined, productRelationship?: (Array<{product?: ComMtnAggregatorModelsRequestProduct | undefined, type?: string | undefined, relationshipType?: string | undefined}>) | undefined, productPrice?: (Array<{href?: string | undefined, priceType?: string | undefined, price?: ({taxIncludedAmount?: ({value?: string | undefined, unit?: string | undefined}) | undefined, dutyFreeAmount?: ({value?: string | undefined, unit?: string | undefined}) | undefined, taxRate?: number | undefined}) | undefined, '@schemaLocation'?: string | undefined}>) | undefined, productTerm?: (Array<{description?: string | undefined, status?: string | undefined, validFor?: ({startDateTime?: string | undefined, endDateTime?: string | undefined}) | undefined, '@type'?: string | undefined}>) | undefined, activationDate?: string | undefined, imsiNumber?: string | undefined, simNumber?: string | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, isCustomerVisible?: boolean | undefined, LoB?: string | undefined, xDir?: string | undefined}; export type ComMtnAggregatorModelsRequestProductSpecification = {id?: string | undefined, '@referredType'?: string | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined, name?: string | undefined, version?: string | undefined, technology?: Array | undefined, LoB?: string | undefined}; export type ComMtnAggregatorModelsRequestNote = {id?: string | undefined, text?: string | undefined}; export type PatchApiPartyInteractionIdArgs = {id: string, systemId?: string | undefined, transactionId?: string | undefined, 'x-country-code'?: string | undefined, body: {creationDate?: string | undefined, id?: string | undefined, href?: string | undefined, interactionDate?: ComMtnAggregatorModelsRequestInteractionDate | undefined, description?: string | undefined, reason?: string | undefined, requestType?: string | undefined, externalIdentifier?: ComMtnAggregatorModelsRequestExternalIdentifier | undefined, status?: string | undefined, direction?: string | undefined, relatedParty?: Array | undefined, relatedChannel?: (Array<{id?: string | undefined, channel?: ({name?: string | undefined, role?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}) | undefined}>) | undefined, interactionItem?: (Array<{id?: string | undefined, item?: ({id?: string | undefined, href?: string | undefined, customFields?: ({productOrderGroup?: Array | undefined, registrationType?: string | undefined}) | undefined, externalSystem?: (Array<{id?: string | undefined, system?: string | undefined, '@type'?: string | undefined, '@baseType'?: string | undefined}>) | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, request?: ({id?: string | undefined, '@referredType'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}) | undefined, createdDate?: string | undefined, orderItem?: (Array<{id?: string | undefined, href?: string | undefined, action?: string | undefined, actionSubType?: string | undefined, productOffering?: ({id?: string | undefined, href?: string | undefined, externalSystem?: Array | undefined, name?: string | undefined, category?: (Array<{name?: string | undefined, version?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}>) | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined}) | undefined, product?: ({id?: string | undefined, href?: string | undefined, customFields?: ComMtnAggregatorModelsRequestCustomFields | undefined, externalSystem?: Array | undefined, name?: string | undefined, startDate?: string | undefined, status?: string | undefined, createdDate?: string | undefined, modifiedDate?: string | undefined, businessType?: string | undefined, technology?: string | undefined, publicIdentifier?: string | undefined, productSpecification?: ({id?: string | undefined, '@referredType'?: string | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined, name?: string | undefined, version?: string | undefined, technology?: Array | undefined, LoB?: string | undefined}) | undefined, productOffering?: ComMtnAggregatorModelsRequestProductOffering | undefined, productOrder?: (Array<{orderItemId?: string | undefined, orderItemAction?: string | undefined, id?: string | undefined, '@referredType'?: string | undefined, '@schemaLocation'?: string | undefined, href?: string | undefined}>) | undefined, channel?: Array | undefined, relatedParty?: Array | undefined, productRelationship?: (Array<{product?: ComMtnAggregatorModelsRequestProduct | undefined, type?: string | undefined, relationshipType?: string | undefined}>) | undefined, productPrice?: (Array<{href?: string | undefined, priceType?: string | undefined, price?: ({taxIncludedAmount?: ({value?: string | undefined, unit?: string | undefined}) | undefined, dutyFreeAmount?: ({value?: string | undefined, unit?: string | undefined}) | undefined, taxRate?: number | undefined}) | undefined, '@schemaLocation'?: string | undefined}>) | undefined, productTerm?: (Array<{description?: string | undefined, status?: string | undefined, validFor?: ({startDateTime?: string | undefined, endDateTime?: string | undefined}) | undefined, '@type'?: string | undefined}>) | undefined, activationDate?: string | undefined, imsiNumber?: string | undefined, simNumber?: string | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, isCustomerVisible?: boolean | undefined, LoB?: string | undefined, xDir?: string | undefined}) | undefined, productSpecification?: ComMtnAggregatorModelsRequestProductSpecification | undefined, modifiable?: boolean | undefined, '@schemaLocation'?: string | undefined}>) | undefined, channel?: Array | undefined, modifiedDate?: string | undefined, state?: string | undefined, relatedParty?: Array | undefined, modifiable?: boolean | undefined, orderDate?: string | undefined, cancellable?: boolean | undefined, requestedStartDate?: string | undefined, role?: string | undefined}) | undefined, interactionItemType?: string | undefined, note?: Array | undefined, creationDate?: string | undefined, actionDate?: string | undefined, reasonCode?: string | undefined, reason?: string | undefined, csrUserName?: string | undefined, csrUserId?: string | undefined, prefLang?: string | undefined, location?: string | undefined, externalUser?: string | undefined}>) | undefined, channel?: Array | undefined, note?: Array | undefined, customerId?: string | undefined, productId?: Array | undefined, publicIdentifier?: Array | undefined, productOrderId?: Array | undefined, createdDate?: string | undefined, modifiedDate?: string | undefined, '@baseType'?: string | undefined, '@type'?: string | undefined, '@schemaLocation'?: string | undefined, retryable?: boolean | undefined, retryableCount?: number | undefined, systemId?: string | undefined, countryCode?: string | undefined, path?: string | undefined}}; export type PatchApiPartyInteractionIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiPartyInteractionIdResponse = z.object({statusCode: z.string().optional(), statusMessage: z.string().optional(), supportMessage: z.string().optional(), transactionId: z.string().optional(), error: z.object({timestamp: z.string().optional(), status: z.string().optional(), error: z.string().optional(), message: z.string().optional(), path: z.string().optional(), existingResourceId: z.string().optional()}).optional(), data: z.object({}).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 }; /** * Forward Incoming Subscriber Message * * PATCH /partyInteraction/{id} */ export const patchApiPartyInteractionId = async (args: PatchApiPartyInteractionIdArgs, options?: PatchApiPartyInteractionIdOptions) => { const {baseUrl = "https://api.mtn.com/v1", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.systemId != null) headers.set("systemId", String(args.systemId)) if (args.transactionId != null) headers.set("transactionId", String(args.transactionId)) if (args['x-country-code'] != null) headers.set("x-country-code", String(args['x-country-code'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/partyInteraction/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiPartyInteractionIdResponse, await res.json()) };