{"version":3,"file":"mux.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/mux.ts"],"sourcesContent":["import Mux from '@mux/mux-node'\n\nimport { getMuxAssetHandler } from '../endpoints/muxAssetHandler'\nimport { getMuxCreateUploadHandler } from '../endpoints/muxCreateUploadHandler'\nimport { getMuxWebhookHandler } from '../endpoints/muxWebhookHandler'\n\nimport { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { MediaCloudPluginOptions } from '../types'\n\nconst magicError: UseMagicErrorReturn = useMagicError({\n  prefix: 'PLUGIN-MEDIA-CLOUD',\n})\n\n/**\n * Creates Mux-related endpoints for asset handling\n * @param args - The arguments for creating Mux endpoints\n * @returns An array of Mux endpoint configurations\n */\ninterface CreateMuxEndpointsArgs {\n  getMuxClient: () => Mux\n  pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createMuxEndpoints(args: CreateMuxEndpointsArgs) {\n  const { getMuxClient, pluginOptions } = args\n\n  const collection = pluginOptions.collection\n  magicError.assert(collection, MediaCloudErrors.COLLECTION_REQUIRED)\n\n  return [\n    {\n      handler: getMuxWebhookHandler({ getMuxClient, collection }),\n      method: 'post' as const,\n      path: '/mux/webhook',\n    },\n    {\n      handler: getMuxCreateUploadHandler({ getMuxClient, pluginOptions }),\n      method: 'post' as const,\n      path: '/mux/upload',\n    },\n    {\n      handler: getMuxAssetHandler({ getMuxClient, collection }),\n      method: 'get' as const,\n      path: '/mux/asset',\n    },\n  ]\n}\n\n/**\n * Validates Mux configuration options\n * @param muxConfig - The Mux configuration to validate\n * @throws {Error} When required Mux configuration is missing\n */\nexport function validateMuxConfig(\n  muxConfig: MediaCloudPluginOptions['mux']\n): void {\n  magicError.assert(muxConfig, MediaCloudErrors.MUX_CONFIG_INCOMPLETE)\n  magicError.assert(muxConfig?.tokenId, MediaCloudErrors.MUX_CONFIG_MISSING)\n  magicError.assert(muxConfig?.tokenSecret, MediaCloudErrors.MUX_CONFIG_MISSING)\n}\n\n/**\n * Creates a new Mux client instance\n * @param muxConfig - The Mux configuration options\n * @returns A configured Mux client\n */\nexport function createMuxClient(\n  muxConfig: MediaCloudPluginOptions['mux']\n): Mux {\n  validateMuxConfig(muxConfig)\n\n  return new Mux({\n    tokenId: muxConfig?.tokenId,\n    tokenSecret: muxConfig?.tokenSecret,\n    webhookSecret: muxConfig?.webhookSecret,\n  })\n}\n"],"mappings":";;;;;;;;AAWA,MAAMA,aAAkC,cAAc,EACpD,QAAQ,sBACT,CAAC;AAYF,SAAgB,mBAAmB,MAA8B;CAC/D,MAAM,EAAE,cAAc,kBAAkB;CAExC,MAAM,aAAa,cAAc;AACjC,YAAW,OAAO,YAAY,iBAAiB,oBAAoB;AAEnE,QAAO;EACL;GACE,SAAS,qBAAqB;IAAE;IAAc;IAAY,CAAC;GAC3D,QAAQ;GACR,MAAM;GACP;EACD;GACE,SAAS,0BAA0B;IAAE;IAAc;IAAe,CAAC;GACnE,QAAQ;GACR,MAAM;GACP;EACD;GACE,SAAS,mBAAmB;IAAE;IAAc;IAAY,CAAC;GACzD,QAAQ;GACR,MAAM;GACP;EACF;;;;;;;AAQH,SAAgB,kBACd,WACM;AACN,YAAW,OAAO,WAAW,iBAAiB,sBAAsB;AACpE,YAAW,OAAO,WAAW,SAAS,iBAAiB,mBAAmB;AAC1E,YAAW,OAAO,WAAW,aAAa,iBAAiB,mBAAmB;;;;;;;AAQhF,SAAgB,gBACd,WACK;AACL,mBAAkB,UAAU;AAE5B,QAAO,IAAI,IAAI;EACb,SAAS,WAAW;EACpB,aAAa,WAAW;EACxB,eAAe,WAAW;EAC3B,CAAC"}