{"version":3,"file":"c8y-ngx-components-static-assets-data.mjs","sources":["../../static-assets/data/static-assets.service.ts","../../static-assets/data/c8y-ngx-components-static-assets-data.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { ApplicationAvailability, ApplicationType, FetchClient, IApplication } from '@c8y/client';\nimport { ApplicationService } from '@c8y/client';\nimport { AppStateService, DroppedFile, FilesService, ZipService } from '@c8y/ngx-components';\nimport { StaticAsset, StaticAssetType } from './static-assets.model';\n\n@Injectable({ providedIn: 'root' })\nexport class StaticAssetsService {\n  readonly fileNames = {\n    contents: 'contents.json',\n    manifest: 'cumulocity.json',\n    exportZipName: 'static-assets.zip'\n  } as const;\n  private listFilesCachePromises: Record<string, Promise<StaticAsset[]>> = {};\n\n  constructor(\n    private appstate: AppStateService,\n    private appService: ApplicationService,\n    private fetchClient: FetchClient,\n    private fileService: FilesService,\n    private zip: ZipService\n  ) {}\n\n  /**\n   * Lists all files of the given type.\n   * Forces a cache renewal.\n   */\n  async listFiles<T extends string = StaticAssetType>(type: T): Promise<StaticAsset[]> {\n    return this.listFilesCached(type, true);\n  }\n\n  /**\n   * Lists all files of the given type.\n   * Uses a cache.\n   */\n  async listFilesCached<T extends string = StaticAssetType>(\n    type: T,\n    forceCacheRenewal = false\n  ): Promise<StaticAsset[]> {\n    if (!this.listFilesCachePromises[type] || forceCacheRenewal) {\n      this.listFilesCachePromises[type] = this._listFiles(type);\n    }\n\n    return await this.listFilesCachePromises[type];\n  }\n\n  /**\n   * Clones all assets of the given type from parent tenants into the current tenant.\n   */\n  async cloneAssetsIntoTenant<T extends string = StaticAssetType>(type: T) {\n    const { data: apps } = await this.appService.list({\n      availability: ApplicationAvailability.SHARED,\n      type: ApplicationType.HOSTED,\n      pageSize: 2000\n    });\n\n    const tenantIdsFromOtherAssetApps = apps\n      .filter(app => {\n        const result =\n          app.owner?.tenant?.id &&\n          app.owner?.tenant?.id !== this.appstate.currentTenant.value?.name &&\n          app.contextPath === this.getContextPath(type, app.owner?.tenant?.id);\n        return result;\n      })\n      .map(app => app.owner?.tenant?.id);\n\n    let filesOfCurrentTenant = await this._listFiles(type);\n\n    let filesToUpload = new Array<File>();\n\n    const oldAssets = new Array<StaticAsset>();\n\n    for (const tenantId of tenantIdsFromOtherAssetApps) {\n      try {\n        const filesOfApp = await this.getContentJSONForType(type, tenantId);\n        oldAssets.push(...filesOfApp);\n        for (const file of filesOfApp) {\n          try {\n            const response = await this.fetchClient.fetch(file.path);\n            if (response.status !== 200) {\n              console.warn(`Failed to get file \"${file.fileName}\" from path ${file.path}`);\n              continue;\n            }\n            const fileContent = await response.blob();\n\n            // remove existing file with same name\n            filesOfCurrentTenant = filesOfCurrentTenant.filter(\n              existingFile => existingFile.fileName !== file.fileName\n            );\n            filesToUpload = filesToUpload.filter(\n              existingFile => existingFile.name !== file.fileName\n            );\n\n            filesToUpload.push(new File([fileContent], file.fileName, { type: file.type }));\n          } catch (e) {\n            console.warn(`Failed to add file \"${file.fileName}\" from tenant ${tenantId}`, e);\n          }\n        }\n      } catch (e) {\n        console.warn(`Failed to get asset files from tenant ${tenantId}`);\n      }\n    }\n\n    if (!filesToUpload.length) {\n      return;\n    }\n\n    const newAssets = await this.addFilesToStaticAssets(type, filesToUpload, filesOfCurrentTenant);\n\n    return { oldAssets, newAssets };\n  }\n\n  /**\n   * Adds the given files to the static assets of the given type.\n   */\n  async addFilesToStaticAssets<T extends string = StaticAssetType>(\n    type: T,\n    files: DroppedFile[] | File[],\n    existingFiles: StaticAsset[],\n    throwErrorOnExistingFiles = true\n  ) {\n    const app = await this.getAppForTenant(type);\n    const filesToAddToContents = new Array<StaticAsset>();\n    const addedAt = new Date().toISOString();\n    const filesToUpload: {\n      path: string;\n      contents: Blob;\n    }[] = [];\n    for (const droppedFile of files) {\n      const file = droppedFile instanceof File ? droppedFile : droppedFile.file;\n      const fileName = file.name.toLowerCase().replace(/[^a-zA-Z0-9\\-\\_\\.]/g, '');\n      const newFile = new File([file], fileName, {\n        type: file.type,\n        lastModified: file.lastModified\n      });\n      if (existingFiles.find(existingFile => existingFile.fileName === fileName)) {\n        if (throwErrorOnExistingFiles) {\n          throw Error(`File with name \"${fileName}\" is already existing.`);\n        }\n        existingFiles = existingFiles.filter(existingFile => existingFile.fileName !== fileName);\n      }\n      const fileExtension = file.name.split('.').pop();\n      filesToAddToContents.push({\n        addedAt,\n        lastModified: file.lastModified,\n        extension: fileExtension,\n        fileName: fileName,\n        originalFileName: file.name,\n        path: `/apps/public/${app.contextPath}/${fileName}`,\n        size: newFile.size,\n        type: newFile.type,\n        hashSum: await this.fileService.getHashSumOfFile(newFile)\n      });\n      filesToUpload.push({\n        contents: newFile,\n        path: fileName\n      });\n    }\n\n    const newFiles: StaticAsset[] = [...existingFiles, ...filesToAddToContents];\n    filesToUpload.push({\n      contents: new File([JSON.stringify(newFiles)], this.fileNames.contents, {\n        type: 'application/json'\n      }),\n      path: this.fileNames.contents\n    });\n    await this.appService.binary(app).updateFiles(filesToUpload);\n    await this.ensureAddedFilesArePresent(filesToAddToContents);\n    return newFiles;\n  }\n\n  /**\n   * Gets the static assets app for the given type.\n   */\n  async getAppForTenant<T extends string = StaticAssetType>(type: T): Promise<IApplication> {\n    const appName = this.getContextPath(type, false);\n    const { data: apps } = await this.appService.listByName(appName);\n    if (!apps.length) {\n      throw Error(`No app with name ${appName} found.`);\n    }\n    return apps[0];\n  }\n\n  private getContentJSONForType<T extends string = StaticAssetType>(\n    type: T,\n    appendTenantId?: string | null | undefined\n  ) {\n    const path = this.getPathForContent(type, appendTenantId);\n    return this.getContentJSONFromPath(path);\n  }\n\n  private async getContentJSONFromPath(path: string): Promise<StaticAsset[]> {\n    const response = await this.fetchClient.fetch(path);\n    if (response.status !== 200) {\n      throw Error(`Failed to retrieve ${path}`);\n    }\n\n    const content = await response.json();\n    return content;\n  }\n\n  private async ensureAddedFilesArePresent(files: StaticAsset[]) {\n    for (const file of files) {\n      await this.ensureFileIsPresent(file);\n    }\n  }\n\n  private async ensureFileIsPresent(file: StaticAsset) {\n    for (let i = 0; i < 12; i++) {\n      try {\n        const currentDate = new Date();\n        const response = await this.fetchClient.fetch(\n          `${file.path}?nocache=${currentDate.getTime()}`\n        );\n        if (response.status !== 200) {\n          await this.sleep(5_000);\n          continue;\n        }\n\n        const blob = await response.blob();\n        const hashSum = await this.fileService.getHashSumOfFile(blob);\n        if (hashSum !== file.hashSum) {\n          await this.sleep(5_000);\n          continue;\n        }\n        return;\n      } catch (e) {\n        console.warn(e);\n        continue;\n      }\n    }\n    throw Error(`Unable to retrieve file from ${file.path}`);\n  }\n\n  private sleep(duration: number): Promise<void> {\n    return new Promise<void>(resolve => setTimeout(() => resolve(), duration));\n  }\n\n  private async _listFiles<T extends string = StaticAssetType>(type: T) {\n    try {\n      const files = await this.getContentJSONForType(type);\n      return files;\n    } catch (e) {\n      console.warn(e);\n    }\n\n    return await this.createEmptyApp(type);\n  }\n\n  private getPathForContent<T extends string = StaticAssetType>(\n    type: T,\n    appendTenantId?: string | null | undefined\n  ): string {\n    const currentDate = new Date();\n    const contextPath = this.getContextPath(type, appendTenantId);\n    return `/apps/public/${contextPath}/${\n      this.fileNames.contents\n    }?nocache=${currentDate.getTime()}`;\n  }\n\n  private getContextPath<T extends string = StaticAssetType>(\n    type: T,\n    appendTenantId?: string | false | undefined\n  ) {\n    let contextPath: string = type + '-assets';\n    const tenantId =\n      appendTenantId === undefined ? this.appstate.currentTenant.value?.name : appendTenantId;\n    if (tenantId) {\n      contextPath = `${contextPath}-${tenantId}`;\n    }\n    return contextPath;\n  }\n\n  private async createEmptyApp<T extends string = StaticAssetType>(\n    type: T,\n    appendTenantId?: string | null | undefined\n  ): Promise<StaticAsset[]> {\n    const name = this.getContextPath(type, false);\n    const contextPath = this.getContextPath(type, appendTenantId);\n    const key = `${contextPath}-key`;\n    const manifest: IApplication = {\n      name,\n      contextPath,\n      key,\n      description: `Application containing static assets used for ${type}.`,\n      noAppSwitcher: true,\n      type: ApplicationType.HOSTED,\n      availability: ApplicationAvailability.MARKET\n    };\n\n    const content = [];\n    const zipFile = await this.zip.createZip([\n      {\n        fileName: `${this.fileNames.manifest}`,\n        blob: new Blob([JSON.stringify(manifest)])\n      },\n      {\n        fileName: `${this.fileNames.contents}`,\n        blob: new Blob([JSON.stringify(content)])\n      }\n    ]);\n    const { data: app } = await this.appService.create(manifest);\n    const { data: appBinary } = await this.appService\n      .binary(app)\n      .upload(zipFile, `empty-${name}.zip`);\n    await this.appService.update({ id: app.id, activeVersionId: appBinary.id as string });\n    return [];\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAOa,mBAAmB,CAAA;IAQ9B,WAAA,CACU,QAAyB,EACzB,UAA8B,EAC9B,WAAwB,EACxB,WAAyB,EACzB,GAAe,EAAA;QAJf,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,GAAG,GAAH,GAAG;AAZJ,QAAA,IAAA,CAAA,SAAS,GAAG;AACnB,YAAA,QAAQ,EAAE,eAAe;AACzB,YAAA,QAAQ,EAAE,iBAAiB;AAC3B,YAAA,aAAa,EAAE;SACP;QACF,IAAA,CAAA,sBAAsB,GAA2C,EAAE;IAQxE;AAEH;;;AAGG;IACH,MAAM,SAAS,CAAqC,IAAO,EAAA;QACzD,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC;IACzC;AAEA;;;AAGG;AACH,IAAA,MAAM,eAAe,CACnB,IAAO,EACP,iBAAiB,GAAG,KAAK,EAAA;QAEzB,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,iBAAiB,EAAE;AAC3D,YAAA,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAC3D;AAEA,QA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