{"version":3,"file":"shared.mjs","names":[],"sources":["../../src/setup/shared.ts"],"sourcesContent":["import { type I18nConfigParams } from '@generaltranslation/react-core/pure';\nimport { type NextI18nCacheParams } from '../i18n-cache/NextI18nCache';\nimport { resolveTranslationLoader } from '../resolvers/resolveTranslationLoader';\nimport { getRuntimeCredentials } from './runtimeCredentials';\n\nexport type NextSetupI18nConfigParams = I18nConfigParams & {\n  cacheUrl?: string | null;\n  _disableDevHotReload?: boolean;\n};\n\n// TODO: better way of communicating from build to runtime\nexport function getParams(): {\n  i18nConfigParams: NextSetupI18nConfigParams;\n  nextI18nCacheParams: NextI18nCacheParams;\n} {\n  // Read from build output\n  const clientConfig = JSON.parse(\n    process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n  );\n  const { projectId, devApiKey, apiKey } = getRuntimeCredentials();\n\n  // I18nConfigParams\n  const i18nConfigParams: NextSetupI18nConfigParams = {\n    defaultLocale: clientConfig.defaultLocale,\n    locales: clientConfig.locales,\n    customMapping: clientConfig.customMapping,\n    runtimeUrl: clientConfig.runtimeUrl,\n    projectId,\n    devApiKey,\n    apiKey,\n    cacheUrl: clientConfig.cacheUrl,\n    _disableDevHotReload: clientConfig._disableDevHotReload,\n    _tagIds: clientConfig._tagIds,\n    localeCookieName: clientConfig.headersAndCookies?.localeCookieName,\n    enableI18nCookieName: clientConfig.headersAndCookies?.enableI18nCookieName,\n  };\n\n  // NextI18nCacheParams\n  const timeout = clientConfig.renderSettings?.timeout;\n  const nextI18nCacheParams: NextI18nCacheParams = {\n    apiKey,\n    devApiKey,\n    projectId,\n    runtimeUrl: clientConfig.runtimeUrl,\n    cacheUrl: clientConfig.cacheUrl,\n    _versionId: clientConfig._versionId,\n    cacheExpiryTime: clientConfig.cacheExpiryTime,\n    // batching config\n    batchConfig: {\n      maxConcurrentRequests: clientConfig.maxConcurrentRequests,\n      maxBatchSize: clientConfig.maxBatchSize,\n      batchInterval: clientConfig.batchInterval,\n    },\n    // runtime translation config\n    runtimeTranslation: {\n      // TODO: reduce redundancy in this config\n      timeout,\n      metadata: {\n        sourceLocale: clientConfig.defaultLocale,\n        timeout,\n        projectId,\n        publish: true,\n        fast: true,\n      },\n    },\n    // loader\n    loadTranslations: createLoadTranslations(),\n  };\n\n  return {\n    i18nConfigParams,\n    nextI18nCacheParams,\n  };\n}\n\nfunction createLoadTranslations() {\n  if (typeof window !== 'undefined') return;\n  return resolveTranslationLoader();\n}\n"],"mappings":";;;AAWA,SAAgB,YAGd;CAEA,MAAM,eAAe,KAAK,MACxB,QAAQ,IAAI,qDAAqD,KAClE;CACD,MAAM,EAAE,WAAW,WAAW,WAAW,uBAAuB;CAGhE,MAAM,mBAA8C;EAClD,eAAe,aAAa;EAC5B,SAAS,aAAa;EACtB,eAAe,aAAa;EAC5B,YAAY,aAAa;EACzB;EACA;EACA;EACA,UAAU,aAAa;EACvB,sBAAsB,aAAa;EACnC,SAAS,aAAa;EACtB,kBAAkB,aAAa,mBAAmB;EAClD,sBAAsB,aAAa,mBAAmB;EACvD;CAGD,MAAM,UAAU,aAAa,gBAAgB;AA+B7C,QAAO;EACL;EACA,qBAAA;GA/BA;GACA;GACA;GACA,YAAY,aAAa;GACzB,UAAU,aAAa;GACvB,YAAY,aAAa;GACzB,iBAAiB,aAAa;GAE9B,aAAa;IACX,uBAAuB,aAAa;IACpC,cAAc,aAAa;IAC3B,eAAe,aAAa;IAC7B;GAED,oBAAoB;IAElB;IACA,UAAU;KACR,cAAc,aAAa;KAC3B;KACA;KACA,SAAS;KACT,MAAM;KACP;IACF;GAED,kBAAkB,wBAAwB;GAKvB;EACpB;;AAGH,SAAS,yBAAyB;AAChC,KAAI,OAAO,WAAW,YAAa;AACnC,QAAO,0BAA0B"}