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,sBAAwB","file":"/npm/@sls-next-n5/s3-static-assets@3.8.0-alpha.2/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@sls-next-n5/s3-static-assets@3.8.0-alpha.2/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.uploadStaticAssetsFromBuild = exports.deleteOldStaticAssets = exports.getAssetDirectoryFileCachePolicies = void 0;\nconst path_1 = __importDefault(require(\"path\"));\nconst readDirectoryFiles_1 = __importDefault(require(\"./lib/readDirectoryFiles\"));\nconst constants_1 = require(\"./lib/constants\");\nconst s3_1 = __importDefault(require(\"./lib/s3\"));\nconst pathToPosix_1 = __importDefault(require(\"./lib/pathToPosix\"));\nconst getPublicAssetCacheControl_1 = __importDefault(require(\"./lib/getPublicAssetCacheControl\"));\nconst getAssetDirectoryFileCachePolicies = (options) => {\n    const { basePath, publicDirectoryCache, serverlessBuildOutDir } = options;\n    const normalizedBasePath = basePath ? basePath.slice(1) : \"\";\n    const assetsOutputDirectory = path_1.default.join(serverlessBuildOutDir, \"assets\");\n    const buildIdPath = path_1.default.join(assetsOutputDirectory, normalizedBasePath, \"BUILD_ID\");\n    const buildIdUpload = {\n        path: buildIdPath,\n        cacheControl: undefined\n    };\n    const nextStaticFiles = (0, readDirectoryFiles_1.default)(path_1.default.join(assetsOutputDirectory, normalizedBasePath, \"_next\", \"static\"));\n    const nextStaticFilesUploads = nextStaticFiles.map((fileItem) => ({\n        path: fileItem.path,\n        cacheControl: constants_1.IMMUTABLE_CACHE_CONTROL_HEADER\n    }));\n    const nextDataFiles = (0, readDirectoryFiles_1.default)(path_1.default.join(assetsOutputDirectory, normalizedBasePath, \"_next\", \"data\"));\n    const nextDataFilesUploads = nextDataFiles.map((fileItem) => ({\n        path: fileItem.path,\n        cacheControl: constants_1.SERVER_CACHE_CONTROL_HEADER\n    }));\n    const htmlPages = (0, readDirectoryFiles_1.default)(path_1.default.join(assetsOutputDirectory, normalizedBasePath, \"static-pages\"));\n    const htmlPagesUploads = htmlPages.map((fileItem) => {\n        const isDynamicFallback = /\\[.*]/.test(fileItem.path);\n        if (isDynamicFallback) {\n            return {\n                path: fileItem.path,\n                cacheControl: constants_1.SERVER_NO_CACHE_CACHE_CONTROL_HEADER\n            };\n        }\n        else {\n            return {\n                path: fileItem.path,\n                cacheControl: constants_1.SERVER_CACHE_CONTROL_HEADER\n            };\n        }\n    });\n    const publicFiles = (0, readDirectoryFiles_1.default)(path_1.default.join(assetsOutputDirectory, normalizedBasePath, \"public\"));\n    const staticFiles = (0, readDirectoryFiles_1.default)(path_1.default.join(assetsOutputDirectory, normalizedBasePath, \"static\"));\n    const publicAndStaticUploads = [...publicFiles, ...staticFiles].map((fileItem) => ({\n        path: fileItem.path,\n        cacheControl: (0, getPublicAssetCacheControl_1.default)(fileItem.path, publicDirectoryCache)\n    }));\n    return [\n        ...nextStaticFilesUploads,\n        ...nextDataFilesUploads,\n        ...htmlPagesUploads,\n        ...publicAndStaticUploads,\n        buildIdUpload\n    ].map(({ cacheControl, path: absolutePath }) => ({\n        cacheControl,\n        path: {\n            relative: path_1.default.relative(assetsOutputDirectory, absolutePath),\n            absolute: absolutePath\n        }\n    }));\n};\nexports.getAssetDirectoryFileCachePolicies = getAssetDirectoryFileCachePolicies;\nconst uploadStaticAssetsFromBuild = async (options) => {\n    const { bucketName, bucketRegion, credentials, basePath, publicDirectoryCache, nextConfigDir } = options;\n    const files = getAssetDirectoryFileCachePolicies({\n        basePath,\n        publicDirectoryCache,\n        serverlessBuildOutDir: path_1.default.join(nextConfigDir, \".serverless_nextjs\")\n    });\n    const s3 = await (0, s3_1.default)({\n        bucketName,\n        bucketRegion,\n        credentials: credentials\n    });\n    return Promise.all(files.map((file) => s3.uploadFile({\n        s3Key: (0, pathToPosix_1.default)(file.path.relative),\n        filePath: file.path.absolute,\n        cacheControl: file.cacheControl\n    })));\n};\nexports.uploadStaticAssetsFromBuild = uploadStaticAssetsFromBuild;\nconst deleteOldStaticAssets = async (options) => {\n    const { bucketName, bucketRegion, basePath } = options;\n    const normalizedBasePathPrefix = basePath ? basePath.slice(1) + \"/\" : \"\";\n    const s3 = await (0, s3_1.default)({\n        bucketName,\n        bucketRegion,\n        credentials: options.credentials\n    });\n    const buildId = await s3.getFile({\n        key: normalizedBasePathPrefix + \"BUILD_ID\"\n    });\n    if (buildId) {\n        const deleteNextDataFiles = s3.deleteFilesByPattern({\n            prefix: `${normalizedBasePathPrefix}_next/data`,\n            pattern: new RegExp(`${normalizedBasePathPrefix}_next/data/.+/`),\n            excludePattern: new RegExp(`${normalizedBasePathPrefix}_next/data/${buildId}/`)\n        });\n        const deleteStaticPageFiles = s3.deleteFilesByPattern({\n            prefix: `${normalizedBasePathPrefix}static-pages`,\n            pattern: new RegExp(`${normalizedBasePathPrefix}static-pages/.+/`),\n            excludePattern: new RegExp(`${normalizedBasePathPrefix}static-pages/${buildId}/`)\n        });\n        await Promise.all([deleteNextDataFiles, deleteStaticPageFiles]);\n    }\n};\nexports.deleteOldStaticAssets = deleteOldStaticAssets;\n"]}