import {z} from 'zod' export type GetApiV2ServersServerNameVhostsVhostNameApplicationsAppNameArgs = {serverName: string, vhostName: string, appName: string}; export type GetApiV2ServersServerNameVhostsVhostNameApplicationsAppNameOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const streamConfigurationConfig = z.object({streamType: z.string(), storageDirExists: z.boolean(), keyDir: z.string(), createStorageDir: z.boolean(), liveStreamPacketizer: z.array(z.string()), serverName: z.string(), storageDir: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string(), httpRandomizeMediaName: z.boolean()}); export const advertisedCandidate = z.object({ipAddress: z.string(), port: z.number().int(), transport: z.string(), type: z.string()}); export const webRTCConfig = z.object({udpBindAddress: z.string(), enablePlay: z.boolean(), preferredCodecsAudio: z.string(), preferredCodecsVideo: z.string(), enableQuery: z.boolean(), debugLog: z.boolean(), serverName: z.string(), saveFieldList: z.array(z.string()).optional(), iceCandidateIpAddresses: z.string(), version: z.string(), enablePublish: z.boolean(), advertisedCandidates: z.array(advertisedCandidate), advertisedCandidatesTimestamp: z.number().int(), enableDataChannels: z.boolean(), enableIceCandidateHarvesting: z.boolean(), enableRemb: z.boolean(), enableSimulcast: z.boolean(), enableTransportCC: z.boolean(), enableWebRTC: z.boolean(), enableWebSocket: z.boolean(), firMessageInterval: z.number().int(), firMessageScheme: z.string(), idleTimeout: z.number().int(), nackDelayMs: z.number().int(), nackEnable: z.boolean(), pliInterval: z.number().int(), renditionDowngradeDebounceMs: z.number().int(), renditionDowngradeMarginPercent: z.number(), renditionInitialRendition: z.string(), renditionSelector: z.string(), renditionSwitchRequestKeyframe: z.boolean(), renditionUpgradeMarginPercent: z.number(), rtxCacheSize: z.number().int(), rtxEnable: z.boolean(), stunServer: z.string(), turnRelay: z.string(), turnRelayPassword: z.string(), turnRelayTrustStore: z.string(), turnRelayTrustStorePassword: z.string(), turnRelayTrustStoreType: z.string(), turnRelayUsername: z.string(), whepBearerToken: z.string(), whipBearerToken: z.string()}); export const shortObject = z.object({id: z.string(), href: z.string()}); export const transcoderTemplatesConfig = z.object({vhostName: z.string(), templates: z.array(shortObject), serverName: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string()}); export const transcoderAppConfig = z.object({profileDir: z.string(), licensed: z.boolean(), templates: transcoderTemplatesConfig, available: z.boolean(), serverName: z.string(), templateDir: z.string(), version: z.string(), createTemplateDir: z.boolean(), licenses: z.number().int(), liveStreamTranscoder: z.string(), templatesInUse: z.string(), licensesInUse: z.number().int(), saveFieldList: z.array(z.string()).optional()}); export const verimatrixStreamMapConfig = z.object({posCount: z.number().int(), keyInterval: z.number().int(), serverName: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string(), streamName: z.string(), resID: z.string(), order: z.number().int()}); export const verimatrixStreamMapsConfig = z.object({filename: z.string(), serverName: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string(), verimatrixStreamMaps: z.array(verimatrixStreamMapConfig)}); export const buyDRMStreamMapConfig = z.object({contentID: z.string(), serverName: z.string(), keyID: z.string(), saveFieldList: z.array(z.string()).optional(), mediaID: z.string(), version: z.string(), streamName: z.string(), order: z.number().int()}); export const buyDRMStreamMapsConfig = z.object({buyDRMStreamMaps: z.array(buyDRMStreamMapConfig), buyDRMStreamNameMapFile: z.string(), serverName: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string()}); export const dRMConfig = z.object({buyDRMProtectMpegDashStreaming: z.boolean(), serverName: z.string(), buyDRMProtectCupertinoStreaming: z.boolean(), version: z.string(), verimatrixCupertinoKeyServerPort: z.number().int(), verimatrixSmoothKeyServerPort: z.number().int(), verimatrixStreamMaps: verimatrixStreamMapsConfig, verimatrixSmoothKeyServerIpAddress: z.string(), licenseType: z.string(), verimatrixCupertinoKeyServerIpAddress: z.string(), buyDRMProtectSmoothStreaming: z.boolean(), buyDRMUserKey: z.string(), inUse: z.boolean(), ezDRMUsername: z.string(), verimatrixProtectSmoothStreaming: z.boolean(), buyDRMStreamMaps: buyDRMStreamMapsConfig, verimatrixCupertinoVODPerSessionKeys: z.boolean(), saveFieldList: z.array(z.string()).optional(), ezDRMPassword: z.string(), verimatrixProtectCupertinoStreaming: z.boolean(), cupertinoEncryptionAPIBased: z.boolean()}); export const moduleConfig = z.object({name: z.string(), serverName: z.string(), description: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string(), class: z.string(), order: z.number().int()}); export const modulesConfig = z.object({moduleList: z.array(moduleConfig), serverName: z.string(), saveFieldList: z.array(z.string()).optional(), version: z.string()}); export const securityConfig = z.object({playMaximumConnections: z.number().int(), publishBlockDuplicateStreamNames: z.boolean(), publishIPWhiteList: z.string(), playAuthenticationMethod: z.string(), serverName: z.string(), clientStreamWriteAccess: z.string(), playIPWhiteList: z.string(), publishRequirePassword: z.boolean(), playIPBlackList: z.string(), version: z.string(), secureTokenVersion: z.number().int(), publishPasswordFile: z.string(), publishValidEncoders: z.string(), secureTokenQueryParametersPrefix: z.string(), secureTokenUseTEAForRTMP: z.boolean(), publishAuthenticationMethod: z.string(), secureTokenHashAlgorithm: z.string(), publishIPBlackList: z.string(), playRequireSecureConnection: z.boolean(), secureTokenOriginSharedSecret: z.string(), saveFieldList: z.array(z.string()).optional(), secureTokenIncludeClientIPInHash: z.boolean(), publishRTMPSecureURL: z.string(), secureTokenSharedSecret: z.string()}); export const dVRConfig = z.object({windowDuration: z.number().int(), dvrMediaCacheEnabled: z.boolean(), dvrEnable: z.boolean(), startRecordingOnStartup: z.boolean(), serverName: z.string(), store: z.string(), version: z.string(), recorders: z.string(), dvrOnlyStreaming: z.boolean(), httpRandomizeMediaName: z.boolean(), licenseType: z.string(), dvrEncryptionSharedSecret: z.string(), inUse: z.boolean(), archiveStrategy: z.string(), storageDir: z.string(), saveFieldList: z.array(z.string()).optional()}); export const applicationConfig = z.object({httpOptimizeFileReads: z.boolean(), captionLiveIngestType: z.string(), streamConfig: streamConfigurationConfig, serverName: z.string(), description: z.string(), closedCaptionLiveOutput608Enabled: z.boolean(), webRTCConfig: webRTCConfig, mediaCacheSourceList: z.array(z.string()), repeaterOriginURL: z.string(), clientStreamReadAccess: z.string(), appType: z.string(), pingTimeout: z.number().int(), vodTimedTextProviders: z.array(z.string()), saveFieldList: z.array(z.string()).optional(), mediaReaderRandomAccessReaderClass: z.string(), mediaReaderBufferSeekIO: z.boolean(), httpStreamers: z.array(z.string()), httpCORSHeadersEnabled: z.boolean(), closedCaptionLiveOutput708Enabled: z.boolean(), avSyncMethod: z.string(), transcoderConfig: transcoderAppConfig, clientStreamWriteAccess: z.string(), repeaterQueryString: z.string(), drmConfig: dRMConfig, version: z.string(), modules: modulesConfig, srtListenerAuthenticationMode: z.string(), maxRTCPWaitTime: z.number().int(), securityConfig: securityConfig, dvrConfig: dVRConfig, applicationTimeout: z.number().int(), name: 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 }; /** * Get app * * GET /v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName} */ export const getApiV2ServersServerNameVhostsVhostNameApplicationsAppName = async (args: GetApiV2ServersServerNameVhostsVhostNameApplicationsAppNameArgs, options?: GetApiV2ServersServerNameVhostsVhostNameApplicationsAppNameOptions) => { const {baseUrl = "http://localhost:8087", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/servers/${encodeURIComponent(String(args.serverName))}/vhosts/${encodeURIComponent(String(args.vhostName))}/applications/${encodeURIComponent(String(args.appName))}${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(applicationConfig, await res.json()) };