@slicemachine/manager 0.24.15-alpha.dependabot-npm-and-yarn-next-14-2-26.1 → 0.24.15-alpha.dependabot-npm-and-yarn-vite-4-5-14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_node_modules/@amplitude/analytics-core/_node_modules/tslib/tslib.es6.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/_node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/lib/esm/plugins/destination.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/lib/esm/plugins/destination.js.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/lib/esm/utils/debug.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/lib/esm/utils/debug.js.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/lib/esm/utils/valid-properties.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-core/lib/esm/utils/valid-properties.js.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-node/_node_modules/tslib/tslib.es6.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-node/_node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-node/lib/esm/transports/http.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/analytics-node/lib/esm/transports/http.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-core/dist/experiment-core.esm.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-core/dist/experiment-core.esm.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/assignment/assignment-service.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/assignment/assignment-service.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/assignment/assignment.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/assignment/assignment.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/cookie.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/cookie.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/cache.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/cache.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/client.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/client.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/fetcher.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/fetcher.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/poller.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/poller.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/remote/client.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/remote/client.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/transport/http.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/transport/http.js.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/util/backoff.cjs.map +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/util/backoff.js.map +1 -1
- package/dist/_node_modules/@msgpack/msgpack/dist.es5_esm/Decoder.cjs.map +1 -1
- package/dist/_node_modules/@msgpack/msgpack/dist.es5_esm/Decoder.js.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/enoent.cjs.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/enoent.js.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/parse.cjs.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/parse.js.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/util/escape.cjs.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/util/escape.js.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/util/readShebang.cjs.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/util/readShebang.js.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/util/resolveCommand.cjs.map +1 -1
- package/dist/_node_modules/cross-spawn/lib/util/resolveCommand.js.map +1 -1
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -1
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js.map +1 -1
- package/dist/_node_modules/execa/_node_modules/onetime/index.cjs.map +1 -1
- package/dist/_node_modules/execa/_node_modules/onetime/index.js.map +1 -1
- package/dist/_node_modules/execa/index.cjs.map +1 -1
- package/dist/_node_modules/execa/index.js.map +1 -1
- package/dist/_node_modules/execa/lib/command.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/command.js.map +1 -1
- package/dist/_node_modules/execa/lib/error.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/error.js.map +1 -1
- package/dist/_node_modules/execa/lib/kill.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/kill.js.map +1 -1
- package/dist/_node_modules/execa/lib/promise.cjs +2 -2
- package/dist/_node_modules/execa/lib/promise.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/promise.js +2 -2
- package/dist/_node_modules/execa/lib/promise.js.map +1 -1
- package/dist/_node_modules/execa/lib/stdio.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/stdio.js.map +1 -1
- package/dist/_node_modules/execa/lib/stream.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/stream.js.map +1 -1
- package/dist/_node_modules/execa/lib/verbose.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/verbose.js.map +1 -1
- package/dist/_node_modules/fetch-blob/file.cjs.map +1 -1
- package/dist/_node_modules/fetch-blob/file.js.map +1 -1
- package/dist/_node_modules/fetch-blob/index.cjs.map +1 -1
- package/dist/_node_modules/fetch-blob/index.js.map +1 -1
- package/dist/_node_modules/fetch-blob/streams.cjs.map +1 -1
- package/dist/_node_modules/fetch-blob/streams.js.map +1 -1
- package/dist/_node_modules/file-type/core.cjs.map +1 -1
- package/dist/_node_modules/file-type/core.js.map +1 -1
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs.map +1 -1
- package/dist/_node_modules/formdata-polyfill/esm.min.js.map +1 -1
- package/dist/_node_modules/get-port/index.cjs.map +1 -1
- package/dist/_node_modules/get-port/index.js.map +1 -1
- package/dist/_node_modules/get-stream/index.cjs.map +1 -1
- package/dist/_node_modules/get-stream/index.js.map +1 -1
- package/dist/_node_modules/human-signals/build/src/realtime.cjs.map +1 -1
- package/dist/_node_modules/human-signals/build/src/realtime.js.map +1 -1
- package/dist/_node_modules/isexe/index.cjs.map +1 -1
- package/dist/_node_modules/isexe/index.js.map +1 -1
- package/dist/_node_modules/mimic-fn/index.cjs.map +1 -1
- package/dist/_node_modules/mimic-fn/index.js.map +1 -1
- package/dist/_node_modules/node-domexception/index.cjs.map +1 -1
- package/dist/_node_modules/node-domexception/index.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/body.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/body.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/headers.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/headers.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/index.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/index.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/request.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/request.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/utils/is.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/utils/is.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -1
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs.map +1 -1
- package/dist/_node_modules/node-fetch/src/utils/referrer.js.map +1 -1
- package/dist/_node_modules/p-limit/index.cjs.map +1 -1
- package/dist/_node_modules/p-limit/index.js.map +1 -1
- package/dist/_node_modules/r19/dist/handleRPCRequest.cjs.map +1 -1
- package/dist/_node_modules/r19/dist/handleRPCRequest.js.map +1 -1
- package/dist/_node_modules/shebang-command/index.cjs.map +1 -1
- package/dist/_node_modules/shebang-command/index.js.map +1 -1
- package/dist/_node_modules/signal-exit/index.cjs.map +1 -1
- package/dist/_node_modules/signal-exit/index.js.map +1 -1
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -1
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -1
- package/dist/_node_modules/which/which.cjs.map +1 -1
- package/dist/_node_modules/which/which.js.map +1 -1
- package/dist/_node_modules/zod/lib/index.cjs.map +1 -1
- package/dist/_node_modules/zod/lib/index.js.map +1 -1
- package/dist/_virtual/_commonjsHelpers.cjs +1 -4
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -1
- package/dist/_virtual/_commonjsHelpers.js +1 -4
- package/dist/_virtual/_commonjsHelpers.js.map +1 -1
- package/dist/auth/PrismicAuthManager.cjs.map +1 -1
- package/dist/auth/PrismicAuthManager.js.map +1 -1
- package/dist/auth/createPrismicAuthManagerMiddleware.cjs.map +1 -1
- package/dist/auth/createPrismicAuthManagerMiddleware.js.map +1 -1
- package/dist/constants/API_ENDPOINTS.cjs.map +1 -1
- package/dist/constants/API_ENDPOINTS.js.map +1 -1
- package/dist/constants/API_TOKENS.cjs.map +1 -1
- package/dist/constants/API_TOKENS.js.map +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/getEnvironmentInfo.cjs.map +1 -1
- package/dist/getEnvironmentInfo.js.map +1 -1
- package/dist/lib/DecodeError.cjs.map +1 -1
- package/dist/lib/DecodeError.js.map +1 -1
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.cjs.map +1 -1
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.js.map +1 -1
- package/dist/lib/fetchGitHubReleaseBodyForRelease.cjs.map +1 -1
- package/dist/lib/fetchGitHubReleaseBodyForRelease.js.map +1 -1
- package/dist/lib/fetchNPMPackageVersions.cjs.map +1 -1
- package/dist/lib/fetchNPMPackageVersions.js.map +1 -1
- package/dist/lib/installDependencies.cjs.map +1 -1
- package/dist/lib/installDependencies.js.map +1 -1
- package/dist/lib/locateFileUpward.cjs.map +1 -1
- package/dist/lib/locateFileUpward.js.map +1 -1
- package/dist/lib/prismicrc.cjs.map +1 -1
- package/dist/lib/prismicrc.js.map +1 -1
- package/dist/managers/SliceMachineManager.cjs.map +1 -1
- package/dist/managers/SliceMachineManager.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/dist/managers/git/GitManager.cjs.map +1 -1
- package/dist/managers/git/GitManager.js.map +1 -1
- package/dist/managers/git/buildGitRepoSpecifier.cjs.map +1 -1
- package/dist/managers/git/buildGitRepoSpecifier.js.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/project/ProjectManager.cjs.map +1 -1
- package/dist/managers/project/ProjectManager.js.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.cjs.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.js.map +1 -1
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.cjs.map +1 -1
- package/dist/managers/sliceTemplateLibrary/SliceTemplateLibraryManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/dist/managers/telemetry/TelemetryManager.cjs.map +1 -1
- package/dist/managers/telemetry/TelemetryManager.js.map +1 -1
- package/dist/managers/versions/VersionsManager.cjs.map +1 -1
- package/dist/managers/versions/VersionsManager.js.map +1 -1
- package/package.json +3 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"installDependencies.cjs","sources":["../../../src/lib/installDependencies.ts"],"sourcesContent":["import { parseNi } from \"@antfu/ni\";\nimport {\n\tExecaChildProcess,\n\texecaCommand,\n\tOptions as ExacaOptions,\n} from \"execa\";\n\nimport { PackageManager } from \"../types\";\n\nconst EXTRA_INSTALL_FLAGS: Record<PackageManager, string[]> = {\n\tnpm: [\"--color=always\", \"--loglevel=info\"], // Default: `--color=true --loglevel=notice`.\n\tpnpm: [], // Default: `--color=auto --loglevel=info`.\n\tyarn: [], // TODO: Add the correct options.\n\t\"yarn@berry\": [], // TODO: Add the correct options.\n\t\"pnpm@6\": [], // // TODO: Add the correct options.\n\tbun: [], // TODO: Add the correct options.\n};\n\ntype InstallDependenciesArgs = {\n\tpackageManager: PackageManager;\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\texeca?: ExacaOptions;\n};\n\ntype InstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\nexport const installDependencies = async (\n\targs: InstallDependenciesArgs,\n): Promise<InstallDependenciesReturnType> => {\n\tconst commandArgs = Object.entries(args.dependencies).map(\n\t\t([pkg, range]) => `${pkg}@${range}`,\n\t);\n\n\tif (commandArgs.length && args.dev) {\n\t\tcommandArgs.unshift(\"-D\");\n\t}\n\n\tcommandArgs.push(...EXTRA_INSTALL_FLAGS[args.packageManager]);\n\n\tconst command = await parseNi(args.packageManager, commandArgs);\n\n\tif (!command) {\n\t\tthrow new Error(\n\t\t\t\"Failed to begin dependency installation (could not parse command)\",\n\t\t\t{\n\t\t\t\tcause: {\n\t\t\t\t\tpackageManager: args.packageManager,\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tconst execaProcess = execaCommand(command, {\n\t\tencoding: \"utf-8\",\n\t\t...args.execa,\n\t});\n\n\treturn {\n\t\texecaProcess,\n\t};\n};\n"],"names":["parseNi","execaCommand"],"mappings":";;;;AASA,MAAM,sBAAwD;AAAA,EAC7D,KAAK,CAAC,kBAAkB,iBAAiB;AAAA;AAAA,EACzC,MAAM,CAAE;AAAA;AAAA,EACR,MAAM,CAAE;AAAA;AAAA,EACR,cAAc,CAAE;AAAA;AAAA,EAChB,UAAU,CAAE;AAAA;AAAA,EACZ,KAAK,CAAE;AAAA;;AAcK,MAAA,sBAAsB,OAClC,SAC2C;AAC3C,QAAM,cAAc,OAAO,QAAQ,KAAK,YAAY,EAAE,IACrD,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,
|
1
|
+
{"version":3,"file":"installDependencies.cjs","sources":["../../../src/lib/installDependencies.ts"],"sourcesContent":["import { parseNi } from \"@antfu/ni\";\nimport {\n\tExecaChildProcess,\n\texecaCommand,\n\tOptions as ExacaOptions,\n} from \"execa\";\n\nimport { PackageManager } from \"../types\";\n\nconst EXTRA_INSTALL_FLAGS: Record<PackageManager, string[]> = {\n\tnpm: [\"--color=always\", \"--loglevel=info\"], // Default: `--color=true --loglevel=notice`.\n\tpnpm: [], // Default: `--color=auto --loglevel=info`.\n\tyarn: [], // TODO: Add the correct options.\n\t\"yarn@berry\": [], // TODO: Add the correct options.\n\t\"pnpm@6\": [], // // TODO: Add the correct options.\n\tbun: [], // TODO: Add the correct options.\n};\n\ntype InstallDependenciesArgs = {\n\tpackageManager: PackageManager;\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\texeca?: ExacaOptions;\n};\n\ntype InstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\nexport const installDependencies = async (\n\targs: InstallDependenciesArgs,\n): Promise<InstallDependenciesReturnType> => {\n\tconst commandArgs = Object.entries(args.dependencies).map(\n\t\t([pkg, range]) => `${pkg}@${range}`,\n\t);\n\n\tif (commandArgs.length && args.dev) {\n\t\tcommandArgs.unshift(\"-D\");\n\t}\n\n\tcommandArgs.push(...EXTRA_INSTALL_FLAGS[args.packageManager]);\n\n\tconst command = await parseNi(args.packageManager, commandArgs);\n\n\tif (!command) {\n\t\tthrow new Error(\n\t\t\t\"Failed to begin dependency installation (could not parse command)\",\n\t\t\t{\n\t\t\t\tcause: {\n\t\t\t\t\tpackageManager: args.packageManager,\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tconst execaProcess = execaCommand(command, {\n\t\tencoding: \"utf-8\",\n\t\t...args.execa,\n\t});\n\n\treturn {\n\t\texecaProcess,\n\t};\n};\n"],"names":["parseNi","execaCommand"],"mappings":";;;;AASA,MAAM,sBAAwD;AAAA,EAC7D,KAAK,CAAC,kBAAkB,iBAAiB;AAAA;AAAA,EACzC,MAAM,CAAE;AAAA;AAAA,EACR,MAAM,CAAE;AAAA;AAAA,EACR,cAAc,CAAE;AAAA;AAAA,EAChB,UAAU,CAAE;AAAA;AAAA,EACZ,KAAK,CAAE;AAAA;;AAcK,MAAA,sBAAsB,OAClC,SAC2C;AAC3C,QAAM,cAAc,OAAO,QAAQ,KAAK,YAAY,EAAE,IACrD,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE;AAGhC,MAAA,YAAY,UAAU,KAAK,KAAK;AACnC,gBAAY,QAAQ,IAAI;AAAA,EACzB;AAEA,cAAY,KAAK,GAAG,oBAAoB,KAAK,cAAc,CAAC;AAE5D,QAAM,UAAU,MAAMA,GAAQ,QAAA,KAAK,gBAAgB,WAAW;AAE9D,MAAI,CAAC,SAAS;AACP,UAAA,IAAI,MACT,qEACA;AAAA,MACC,OAAO;AAAA,QACN,gBAAgB,KAAK;AAAA,QACrB,cAAc,KAAK;AAAA,MACnB;AAAA,IAAA,CACD;AAAA,EAEH;AAEM,QAAA,eAAeC,mBAAa,SAAS;AAAA,IAC1C,UAAU;AAAA,IACV,GAAG,KAAK;AAAA,EAAA,CACR;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"installDependencies.js","sources":["../../../src/lib/installDependencies.ts"],"sourcesContent":["import { parseNi } from \"@antfu/ni\";\nimport {\n\tExecaChildProcess,\n\texecaCommand,\n\tOptions as ExacaOptions,\n} from \"execa\";\n\nimport { PackageManager } from \"../types\";\n\nconst EXTRA_INSTALL_FLAGS: Record<PackageManager, string[]> = {\n\tnpm: [\"--color=always\", \"--loglevel=info\"], // Default: `--color=true --loglevel=notice`.\n\tpnpm: [], // Default: `--color=auto --loglevel=info`.\n\tyarn: [], // TODO: Add the correct options.\n\t\"yarn@berry\": [], // TODO: Add the correct options.\n\t\"pnpm@6\": [], // // TODO: Add the correct options.\n\tbun: [], // TODO: Add the correct options.\n};\n\ntype InstallDependenciesArgs = {\n\tpackageManager: PackageManager;\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\texeca?: ExacaOptions;\n};\n\ntype InstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\nexport const installDependencies = async (\n\targs: InstallDependenciesArgs,\n): Promise<InstallDependenciesReturnType> => {\n\tconst commandArgs = Object.entries(args.dependencies).map(\n\t\t([pkg, range]) => `${pkg}@${range}`,\n\t);\n\n\tif (commandArgs.length && args.dev) {\n\t\tcommandArgs.unshift(\"-D\");\n\t}\n\n\tcommandArgs.push(...EXTRA_INSTALL_FLAGS[args.packageManager]);\n\n\tconst command = await parseNi(args.packageManager, commandArgs);\n\n\tif (!command) {\n\t\tthrow new Error(\n\t\t\t\"Failed to begin dependency installation (could not parse command)\",\n\t\t\t{\n\t\t\t\tcause: {\n\t\t\t\t\tpackageManager: args.packageManager,\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tconst execaProcess = execaCommand(command, {\n\t\tencoding: \"utf-8\",\n\t\t...args.execa,\n\t});\n\n\treturn {\n\t\texecaProcess,\n\t};\n};\n"],"names":[],"mappings":";;AASA,MAAM,sBAAwD;AAAA,EAC7D,KAAK,CAAC,kBAAkB,iBAAiB;AAAA;AAAA,EACzC,MAAM,CAAE;AAAA;AAAA,EACR,MAAM,CAAE;AAAA;AAAA,EACR,cAAc,CAAE;AAAA;AAAA,EAChB,UAAU,CAAE;AAAA;AAAA,EACZ,KAAK,CAAE;AAAA;;AAcK,MAAA,sBAAsB,OAClC,SAC2C;AAC3C,QAAM,cAAc,OAAO,QAAQ,KAAK,YAAY,EAAE,IACrD,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,
|
1
|
+
{"version":3,"file":"installDependencies.js","sources":["../../../src/lib/installDependencies.ts"],"sourcesContent":["import { parseNi } from \"@antfu/ni\";\nimport {\n\tExecaChildProcess,\n\texecaCommand,\n\tOptions as ExacaOptions,\n} from \"execa\";\n\nimport { PackageManager } from \"../types\";\n\nconst EXTRA_INSTALL_FLAGS: Record<PackageManager, string[]> = {\n\tnpm: [\"--color=always\", \"--loglevel=info\"], // Default: `--color=true --loglevel=notice`.\n\tpnpm: [], // Default: `--color=auto --loglevel=info`.\n\tyarn: [], // TODO: Add the correct options.\n\t\"yarn@berry\": [], // TODO: Add the correct options.\n\t\"pnpm@6\": [], // // TODO: Add the correct options.\n\tbun: [], // TODO: Add the correct options.\n};\n\ntype InstallDependenciesArgs = {\n\tpackageManager: PackageManager;\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\texeca?: ExacaOptions;\n};\n\ntype InstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\nexport const installDependencies = async (\n\targs: InstallDependenciesArgs,\n): Promise<InstallDependenciesReturnType> => {\n\tconst commandArgs = Object.entries(args.dependencies).map(\n\t\t([pkg, range]) => `${pkg}@${range}`,\n\t);\n\n\tif (commandArgs.length && args.dev) {\n\t\tcommandArgs.unshift(\"-D\");\n\t}\n\n\tcommandArgs.push(...EXTRA_INSTALL_FLAGS[args.packageManager]);\n\n\tconst command = await parseNi(args.packageManager, commandArgs);\n\n\tif (!command) {\n\t\tthrow new Error(\n\t\t\t\"Failed to begin dependency installation (could not parse command)\",\n\t\t\t{\n\t\t\t\tcause: {\n\t\t\t\t\tpackageManager: args.packageManager,\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tconst execaProcess = execaCommand(command, {\n\t\tencoding: \"utf-8\",\n\t\t...args.execa,\n\t});\n\n\treturn {\n\t\texecaProcess,\n\t};\n};\n"],"names":[],"mappings":";;AASA,MAAM,sBAAwD;AAAA,EAC7D,KAAK,CAAC,kBAAkB,iBAAiB;AAAA;AAAA,EACzC,MAAM,CAAE;AAAA;AAAA,EACR,MAAM,CAAE;AAAA;AAAA,EACR,cAAc,CAAE;AAAA;AAAA,EAChB,UAAU,CAAE;AAAA;AAAA,EACZ,KAAK,CAAE;AAAA;;AAcK,MAAA,sBAAsB,OAClC,SAC2C;AAC3C,QAAM,cAAc,OAAO,QAAQ,KAAK,YAAY,EAAE,IACrD,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE;AAGhC,MAAA,YAAY,UAAU,KAAK,KAAK;AACnC,gBAAY,QAAQ,IAAI;AAAA,EACzB;AAEA,cAAY,KAAK,GAAG,oBAAoB,KAAK,cAAc,CAAC;AAE5D,QAAM,UAAU,MAAM,QAAQ,KAAK,gBAAgB,WAAW;AAE9D,MAAI,CAAC,SAAS;AACP,UAAA,IAAI,MACT,qEACA;AAAA,MACC,OAAO;AAAA,QACN,gBAAgB,KAAK;AAAA,QACrB,cAAc,KAAK;AAAA,MACnB;AAAA,IAAA,CACD;AAAA,EAEH;AAEM,QAAA,eAAe,aAAa,SAAS;AAAA,IAC1C,UAAU;AAAA,IACV,GAAG,KAAK;AAAA,EAAA,CACR;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"locateFileUpward.cjs","sources":["../../../src/lib/locateFileUpward.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport { castArray } from \"./castArray\";\n\ntype LocateFileUpwardConfig = {\n\tstartDir?: string;\n\tstopDir?: string;\n\t/**\n\t * @internal\n\t */\n\t_originalStartDir?: string;\n};\n\nexport const locateFileUpward = async (\n\tfilePathOrPaths: string | readonly string[],\n\t{\n\t\tstartDir = process.cwd(),\n\t\tstopDir = path.resolve(startDir, \"/\"),\n\t\t_originalStartDir,\n\t}: LocateFileUpwardConfig = {},\n): Promise<string> => {\n\tconst originalStartDir = _originalStartDir ?? startDir;\n\n\tconst filePaths = castArray(filePathOrPaths);\n\n\tfor (const filePath of filePaths) {\n\t\tconst resolvedFilePath = path.resolve(startDir, filePath);\n\t\ttry {\n\t\t\tawait fs.access(resolvedFilePath);\n\n\t\t\treturn resolvedFilePath;\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\tif (startDir === stopDir) {\n\t\tconst formattedFilePaths = filePaths\n\t\t\t.map((filePath) => \"`\" + filePath + \"`\")\n\t\t\t.join(\" or \");\n\n\t\tthrow new Error(\n\t\t\t`Could not locate ${formattedFilePaths} between \\`${originalStartDir}\\` and \\`${stopDir}\\`.`,\n\t\t);\n\t}\n\n\treturn locateFileUpward(filePathOrPaths, {\n\t\tstartDir: path.resolve(startDir, \"..\"),\n\t\tstopDir,\n\t\t_originalStartDir: originalStartDir,\n\t});\n};\n"],"names":["path","castArray","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,mBAAmB,OAC/B,iBACA,EACC,WAAW,QAAQ,IAAG,GACtB,UAAUA,gBAAK,QAAQ,UAAU,GAAG,GACpC,kBAC2B,IAAA,CAAA,MACR;AACpB,QAAM,mBAAmB,qBAAqB;AAExC,QAAA,YAAYC,oBAAU,eAAe;AAE3C,aAAW,YAAY,WAAW;AACjC,UAAM,mBAAmBD,gBAAK,QAAQ,UAAU,QAAQ;AACpD,QAAA;AACG,YAAAE,cAAG,OAAO,gBAAgB;AAEzB,aAAA;AAAA,IAAA,
|
1
|
+
{"version":3,"file":"locateFileUpward.cjs","sources":["../../../src/lib/locateFileUpward.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport { castArray } from \"./castArray\";\n\ntype LocateFileUpwardConfig = {\n\tstartDir?: string;\n\tstopDir?: string;\n\t/**\n\t * @internal\n\t */\n\t_originalStartDir?: string;\n};\n\nexport const locateFileUpward = async (\n\tfilePathOrPaths: string | readonly string[],\n\t{\n\t\tstartDir = process.cwd(),\n\t\tstopDir = path.resolve(startDir, \"/\"),\n\t\t_originalStartDir,\n\t}: LocateFileUpwardConfig = {},\n): Promise<string> => {\n\tconst originalStartDir = _originalStartDir ?? startDir;\n\n\tconst filePaths = castArray(filePathOrPaths);\n\n\tfor (const filePath of filePaths) {\n\t\tconst resolvedFilePath = path.resolve(startDir, filePath);\n\t\ttry {\n\t\t\tawait fs.access(resolvedFilePath);\n\n\t\t\treturn resolvedFilePath;\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\tif (startDir === stopDir) {\n\t\tconst formattedFilePaths = filePaths\n\t\t\t.map((filePath) => \"`\" + filePath + \"`\")\n\t\t\t.join(\" or \");\n\n\t\tthrow new Error(\n\t\t\t`Could not locate ${formattedFilePaths} between \\`${originalStartDir}\\` and \\`${stopDir}\\`.`,\n\t\t);\n\t}\n\n\treturn locateFileUpward(filePathOrPaths, {\n\t\tstartDir: path.resolve(startDir, \"..\"),\n\t\tstopDir,\n\t\t_originalStartDir: originalStartDir,\n\t});\n};\n"],"names":["path","castArray","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,mBAAmB,OAC/B,iBACA,EACC,WAAW,QAAQ,IAAG,GACtB,UAAUA,gBAAK,QAAQ,UAAU,GAAG,GACpC,kBAC2B,IAAA,CAAA,MACR;AACpB,QAAM,mBAAmB,qBAAqB;AAExC,QAAA,YAAYC,oBAAU,eAAe;AAE3C,aAAW,YAAY,WAAW;AACjC,UAAM,mBAAmBD,gBAAK,QAAQ,UAAU,QAAQ;AACpD,QAAA;AACG,YAAAE,cAAG,OAAO,gBAAgB;AAEzB,aAAA;AAAA,IAAA,QACA;AACP;AAAA,IACD;AAAA,EACD;AAEA,MAAI,aAAa,SAAS;AACnB,UAAA,qBAAqB,UACzB,IAAI,CAAC,aAAa,MAAM,WAAW,GAAG,EACtC,KAAK,MAAM;AAEP,UAAA,IAAI,MACT,oBAAoB,kBAAkB,cAAc,gBAAgB,YAAY,OAAO,KAAK;AAAA,EAE9F;AAEA,SAAO,iBAAiB,iBAAiB;AAAA,IACxC,UAAUF,gBAAK,QAAQ,UAAU,IAAI;AAAA,IACrC;AAAA,IACA,mBAAmB;AAAA,EAAA,CACnB;AACF;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"locateFileUpward.js","sources":["../../../src/lib/locateFileUpward.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport { castArray } from \"./castArray\";\n\ntype LocateFileUpwardConfig = {\n\tstartDir?: string;\n\tstopDir?: string;\n\t/**\n\t * @internal\n\t */\n\t_originalStartDir?: string;\n};\n\nexport const locateFileUpward = async (\n\tfilePathOrPaths: string | readonly string[],\n\t{\n\t\tstartDir = process.cwd(),\n\t\tstopDir = path.resolve(startDir, \"/\"),\n\t\t_originalStartDir,\n\t}: LocateFileUpwardConfig = {},\n): Promise<string> => {\n\tconst originalStartDir = _originalStartDir ?? startDir;\n\n\tconst filePaths = castArray(filePathOrPaths);\n\n\tfor (const filePath of filePaths) {\n\t\tconst resolvedFilePath = path.resolve(startDir, filePath);\n\t\ttry {\n\t\t\tawait fs.access(resolvedFilePath);\n\n\t\t\treturn resolvedFilePath;\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\tif (startDir === stopDir) {\n\t\tconst formattedFilePaths = filePaths\n\t\t\t.map((filePath) => \"`\" + filePath + \"`\")\n\t\t\t.join(\" or \");\n\n\t\tthrow new Error(\n\t\t\t`Could not locate ${formattedFilePaths} between \\`${originalStartDir}\\` and \\`${stopDir}\\`.`,\n\t\t);\n\t}\n\n\treturn locateFileUpward(filePathOrPaths, {\n\t\tstartDir: path.resolve(startDir, \"..\"),\n\t\tstopDir,\n\t\t_originalStartDir: originalStartDir,\n\t});\n};\n"],"names":[],"mappings":";;;AAcO,MAAM,mBAAmB,OAC/B,iBACA,EACC,WAAW,QAAQ,IAAG,GACtB,UAAU,KAAK,QAAQ,UAAU,GAAG,GACpC,kBAC2B,IAAA,CAAA,MACR;AACpB,QAAM,mBAAmB,qBAAqB;AAExC,QAAA,YAAY,UAAU,eAAe;AAE3C,aAAW,YAAY,WAAW;AACjC,UAAM,mBAAmB,KAAK,QAAQ,UAAU,QAAQ;AACpD,QAAA;AACG,YAAA,GAAG,OAAO,gBAAgB;AAEzB,aAAA;AAAA,IAAA,
|
1
|
+
{"version":3,"file":"locateFileUpward.js","sources":["../../../src/lib/locateFileUpward.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport { castArray } from \"./castArray\";\n\ntype LocateFileUpwardConfig = {\n\tstartDir?: string;\n\tstopDir?: string;\n\t/**\n\t * @internal\n\t */\n\t_originalStartDir?: string;\n};\n\nexport const locateFileUpward = async (\n\tfilePathOrPaths: string | readonly string[],\n\t{\n\t\tstartDir = process.cwd(),\n\t\tstopDir = path.resolve(startDir, \"/\"),\n\t\t_originalStartDir,\n\t}: LocateFileUpwardConfig = {},\n): Promise<string> => {\n\tconst originalStartDir = _originalStartDir ?? startDir;\n\n\tconst filePaths = castArray(filePathOrPaths);\n\n\tfor (const filePath of filePaths) {\n\t\tconst resolvedFilePath = path.resolve(startDir, filePath);\n\t\ttry {\n\t\t\tawait fs.access(resolvedFilePath);\n\n\t\t\treturn resolvedFilePath;\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\tif (startDir === stopDir) {\n\t\tconst formattedFilePaths = filePaths\n\t\t\t.map((filePath) => \"`\" + filePath + \"`\")\n\t\t\t.join(\" or \");\n\n\t\tthrow new Error(\n\t\t\t`Could not locate ${formattedFilePaths} between \\`${originalStartDir}\\` and \\`${stopDir}\\`.`,\n\t\t);\n\t}\n\n\treturn locateFileUpward(filePathOrPaths, {\n\t\tstartDir: path.resolve(startDir, \"..\"),\n\t\tstopDir,\n\t\t_originalStartDir: originalStartDir,\n\t});\n};\n"],"names":[],"mappings":";;;AAcO,MAAM,mBAAmB,OAC/B,iBACA,EACC,WAAW,QAAQ,IAAG,GACtB,UAAU,KAAK,QAAQ,UAAU,GAAG,GACpC,kBAC2B,IAAA,CAAA,MACR;AACpB,QAAM,mBAAmB,qBAAqB;AAExC,QAAA,YAAY,UAAU,eAAe;AAE3C,aAAW,YAAY,WAAW;AACjC,UAAM,mBAAmB,KAAK,QAAQ,UAAU,QAAQ;AACpD,QAAA;AACG,YAAA,GAAG,OAAO,gBAAgB;AAEzB,aAAA;AAAA,IAAA,QACA;AACP;AAAA,IACD;AAAA,EACD;AAEA,MAAI,aAAa,SAAS;AACnB,UAAA,qBAAqB,UACzB,IAAI,CAAC,aAAa,MAAM,WAAW,GAAG,EACtC,KAAK,MAAM;AAEP,UAAA,IAAI,MACT,oBAAoB,kBAAkB,cAAc,gBAAgB,YAAY,OAAO,KAAK;AAAA,EAE9F;AAEA,SAAO,iBAAiB,iBAAiB;AAAA,IACxC,UAAU,KAAK,QAAQ,UAAU,IAAI;AAAA,IACrC;AAAA,IACA,mBAAmB;AAAA,EAAA,CACnB;AACF;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prismicrc.cjs","sources":["../../../src/lib/prismicrc.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as t from \"io-ts\";\nimport * as rc9 from \"rc9\";\n\nimport { decode } from \"./decode\";\n\nconst PRISMICRC = \".prismicrc\";\n\nconst Prismicrc = t.partial({\n\ttelemetry: t.boolean,\n});\ntype Prismicrc = t.TypeOf<typeof Prismicrc>;\n\nexport const readRawPrismicrc = (dir?: string): Prismicrc => {\n\tconst rawPrismicrc = dir\n\t\t? rc9.read({ dir, name: PRISMICRC })\n\t\t: rc9.readUser(PRISMICRC);\n\n\tconst { value: prismicrc, error } = decode(Prismicrc, rawPrismicrc);\n\n\tif (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to parse ${\n\t\t\t\tdir ? path.resolve(dir, PRISMICRC) : `~/${PRISMICRC}`\n\t\t\t}: ${error.errors.join(\", \")}`,\n\t\t);\n\t}\n\n\treturn prismicrc;\n};\n\nexport const readPrismicrc = (dir: string): Prismicrc => {\n\tconst userPrismicrc = readRawPrismicrc();\n\tconst projectPrismicrc = readRawPrismicrc(dir);\n\n\treturn {\n\t\t...userPrismicrc,\n\t\t...projectPrismicrc,\n\t};\n};\n\nexport const writePrismicrc = (config: Prismicrc, dir?: string): void => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\tdir\n\t\t? rc9.write(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.writeUser(validatedConfig, PRISMICRC);\n};\n\nexport const updatePrismicrc = (config: Prismicrc, dir?: string): Prismicrc => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\treturn dir\n\t\t? rc9.update(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.updateUser(validatedConfig, PRISMICRC);\n};\n"],"names":["t","rc9","decode","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,YAAY;AAElB,MAAM,YAAYA,aAAE,QAAQ;AAAA,EAC3B,WAAWA,aAAE;AACb,CAAA;AAGY,MAAA,mBAAmB,CAAC,QAA2B;AAC3D,QAAM,eAAe,MAClBC,eAAI,KAAK,EAAE,KAAK,MAAM,UAAW,CAAA,IACjCA,eAAI,SAAS,SAAS;AAEzB,QAAM,EAAE,OAAO,WAAW,MAAU,IAAAC,cAAO,WAAW,YAAY;AAElE,MAAI,OAAO;AACV,UAAM,IAAI,MACT,mBACC,MAAMC,gBAAK,QAAQ,KAAK,SAAS,IAAI,KAAK,
|
1
|
+
{"version":3,"file":"prismicrc.cjs","sources":["../../../src/lib/prismicrc.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as t from \"io-ts\";\nimport * as rc9 from \"rc9\";\n\nimport { decode } from \"./decode\";\n\nconst PRISMICRC = \".prismicrc\";\n\nconst Prismicrc = t.partial({\n\ttelemetry: t.boolean,\n});\ntype Prismicrc = t.TypeOf<typeof Prismicrc>;\n\nexport const readRawPrismicrc = (dir?: string): Prismicrc => {\n\tconst rawPrismicrc = dir\n\t\t? rc9.read({ dir, name: PRISMICRC })\n\t\t: rc9.readUser(PRISMICRC);\n\n\tconst { value: prismicrc, error } = decode(Prismicrc, rawPrismicrc);\n\n\tif (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to parse ${\n\t\t\t\tdir ? path.resolve(dir, PRISMICRC) : `~/${PRISMICRC}`\n\t\t\t}: ${error.errors.join(\", \")}`,\n\t\t);\n\t}\n\n\treturn prismicrc;\n};\n\nexport const readPrismicrc = (dir: string): Prismicrc => {\n\tconst userPrismicrc = readRawPrismicrc();\n\tconst projectPrismicrc = readRawPrismicrc(dir);\n\n\treturn {\n\t\t...userPrismicrc,\n\t\t...projectPrismicrc,\n\t};\n};\n\nexport const writePrismicrc = (config: Prismicrc, dir?: string): void => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\tdir\n\t\t? rc9.write(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.writeUser(validatedConfig, PRISMICRC);\n};\n\nexport const updatePrismicrc = (config: Prismicrc, dir?: string): Prismicrc => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\treturn dir\n\t\t? rc9.update(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.updateUser(validatedConfig, PRISMICRC);\n};\n"],"names":["t","rc9","decode","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,YAAY;AAElB,MAAM,YAAYA,aAAE,QAAQ;AAAA,EAC3B,WAAWA,aAAE;AACb,CAAA;AAGY,MAAA,mBAAmB,CAAC,QAA2B;AAC3D,QAAM,eAAe,MAClBC,eAAI,KAAK,EAAE,KAAK,MAAM,UAAW,CAAA,IACjCA,eAAI,SAAS,SAAS;AAEzB,QAAM,EAAE,OAAO,WAAW,MAAU,IAAAC,cAAO,WAAW,YAAY;AAElE,MAAI,OAAO;AACV,UAAM,IAAI,MACT,mBACC,MAAMC,gBAAK,QAAQ,KAAK,SAAS,IAAI,KAAK,SAAS,EACpD,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,EAEhC;AAEO,SAAA;AACR;AAEa,MAAA,gBAAgB,CAAC,QAA0B;AACvD,QAAM,gBAAgB;AAChB,QAAA,mBAAmB,iBAAiB,GAAG;AAEtC,SAAA;AAAA,IACN,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAEL;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prismicrc.js","sources":["../../../src/lib/prismicrc.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as t from \"io-ts\";\nimport * as rc9 from \"rc9\";\n\nimport { decode } from \"./decode\";\n\nconst PRISMICRC = \".prismicrc\";\n\nconst Prismicrc = t.partial({\n\ttelemetry: t.boolean,\n});\ntype Prismicrc = t.TypeOf<typeof Prismicrc>;\n\nexport const readRawPrismicrc = (dir?: string): Prismicrc => {\n\tconst rawPrismicrc = dir\n\t\t? rc9.read({ dir, name: PRISMICRC })\n\t\t: rc9.readUser(PRISMICRC);\n\n\tconst { value: prismicrc, error } = decode(Prismicrc, rawPrismicrc);\n\n\tif (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to parse ${\n\t\t\t\tdir ? path.resolve(dir, PRISMICRC) : `~/${PRISMICRC}`\n\t\t\t}: ${error.errors.join(\", \")}`,\n\t\t);\n\t}\n\n\treturn prismicrc;\n};\n\nexport const readPrismicrc = (dir: string): Prismicrc => {\n\tconst userPrismicrc = readRawPrismicrc();\n\tconst projectPrismicrc = readRawPrismicrc(dir);\n\n\treturn {\n\t\t...userPrismicrc,\n\t\t...projectPrismicrc,\n\t};\n};\n\nexport const writePrismicrc = (config: Prismicrc, dir?: string): void => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\tdir\n\t\t? rc9.write(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.writeUser(validatedConfig, PRISMICRC);\n};\n\nexport const updatePrismicrc = (config: Prismicrc, dir?: string): Prismicrc => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\treturn dir\n\t\t? rc9.update(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.updateUser(validatedConfig, PRISMICRC);\n};\n"],"names":[],"mappings":";;;;AAMA,MAAM,YAAY;AAElB,MAAM,YAAY,EAAE,QAAQ;AAAA,EAC3B,WAAW,EAAE;AACb,CAAA;AAGY,MAAA,mBAAmB,CAAC,QAA2B;AAC3D,QAAM,eAAe,MAClB,IAAI,KAAK,EAAE,KAAK,MAAM,UAAW,CAAA,IACjC,IAAI,SAAS,SAAS;AAEzB,QAAM,EAAE,OAAO,WAAW,MAAU,IAAA,OAAO,WAAW,YAAY;AAElE,MAAI,OAAO;AACV,UAAM,IAAI,MACT,mBACC,MAAM,KAAK,QAAQ,KAAK,SAAS,IAAI,KAAK,
|
1
|
+
{"version":3,"file":"prismicrc.js","sources":["../../../src/lib/prismicrc.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as t from \"io-ts\";\nimport * as rc9 from \"rc9\";\n\nimport { decode } from \"./decode\";\n\nconst PRISMICRC = \".prismicrc\";\n\nconst Prismicrc = t.partial({\n\ttelemetry: t.boolean,\n});\ntype Prismicrc = t.TypeOf<typeof Prismicrc>;\n\nexport const readRawPrismicrc = (dir?: string): Prismicrc => {\n\tconst rawPrismicrc = dir\n\t\t? rc9.read({ dir, name: PRISMICRC })\n\t\t: rc9.readUser(PRISMICRC);\n\n\tconst { value: prismicrc, error } = decode(Prismicrc, rawPrismicrc);\n\n\tif (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to parse ${\n\t\t\t\tdir ? path.resolve(dir, PRISMICRC) : `~/${PRISMICRC}`\n\t\t\t}: ${error.errors.join(\", \")}`,\n\t\t);\n\t}\n\n\treturn prismicrc;\n};\n\nexport const readPrismicrc = (dir: string): Prismicrc => {\n\tconst userPrismicrc = readRawPrismicrc();\n\tconst projectPrismicrc = readRawPrismicrc(dir);\n\n\treturn {\n\t\t...userPrismicrc,\n\t\t...projectPrismicrc,\n\t};\n};\n\nexport const writePrismicrc = (config: Prismicrc, dir?: string): void => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\tdir\n\t\t? rc9.write(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.writeUser(validatedConfig, PRISMICRC);\n};\n\nexport const updatePrismicrc = (config: Prismicrc, dir?: string): Prismicrc => {\n\tconst { value: validatedConfig, error } = decode(Prismicrc, config);\n\n\tif (error) {\n\t\tthrow new Error(`Failed to validate config: ${error.errors.join(\", \")}`);\n\t}\n\n\treturn dir\n\t\t? rc9.update(validatedConfig, { dir, name: PRISMICRC })\n\t\t: rc9.updateUser(validatedConfig, PRISMICRC);\n};\n"],"names":[],"mappings":";;;;AAMA,MAAM,YAAY;AAElB,MAAM,YAAY,EAAE,QAAQ;AAAA,EAC3B,WAAW,EAAE;AACb,CAAA;AAGY,MAAA,mBAAmB,CAAC,QAA2B;AAC3D,QAAM,eAAe,MAClB,IAAI,KAAK,EAAE,KAAK,MAAM,UAAW,CAAA,IACjC,IAAI,SAAS,SAAS;AAEzB,QAAM,EAAE,OAAO,WAAW,MAAU,IAAA,OAAO,WAAW,YAAY;AAElE,MAAI,OAAO;AACV,UAAM,IAAI,MACT,mBACC,MAAM,KAAK,QAAQ,KAAK,SAAS,IAAI,KAAK,SAAS,EACpD,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,EAEhC;AAEO,SAAA;AACR;AAEa,MAAA,gBAAgB,CAAC,QAA0B;AACvD,QAAM,gBAAgB;AAChB,QAAA,mBAAmB,iBAAiB,GAAG;AAEtC,SAAA;AAAA,IACN,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAEL;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SliceMachineManager.cjs","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\nimport { SliceTemplateLibraryManager } from \"./sliceTemplateLibrary/SliceTemplateLibraryManager\";\nimport { GitManager } from \"./git/GitManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\tsliceTemplateLibrary: SliceTemplateLibraryManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\tgit: GitManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\t\tthis.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.git = new GitManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\terror instanceof prismicCustomTypesClient.UnauthorizedError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["createPrismicAuthManager","UserManager","PrismicRepositoryManager","PluginsManager","ProjectManager","CustomTypesManager","SlicesManager","SnippetsManager","ScreenshotsManager","SimulatorManager","DocumentationManager","SliceTemplateLibraryManager","VersionsManager","TelemetryManager","GitManager","API_ENDPOINTS","sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices","prismicCustomTypesClient","buildPrismicRepositoryAPIEndpoint","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkGa,oBAAmB;AAAA,EAsB/B,YAAY,MAAyC;AArB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsBA,yBAAAA;AAEtB,SAAA,OAAO,IAAIC,YAAA,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAIC,yBAAA,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAIC,eAAA,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAIC,eAAA,eAAe,IAAI;AACjC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAIC,cAAA,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AACnC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,YAAY,IAAIC,iBAAA,iBAAiB,IAAI;AACrC,SAAA,gBAAgB,IAAIC,qBAAA,qBAAqB,IAAI;AAC7C,SAAA,uBAAuB,IAAIC,4BAAA,4BAA4B,IAAI;AAE3D,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AAEnC,SAAA,YAAY,IAAIC,iBAAA,iBAAiB,IAAI;AAErC,SAAA,MAAM,IAAIC,WAAA,WAAW,IAAI;AAE9B,SAAK,OAA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AAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACvB;AAAA,MACA,CAAA,CAAC;AAAA,IAEJ;AAEO,WAAA;AAAA,EACR;AACA;;"}
|
1
|
+
{"version":3,"file":"SliceMachineManager.cjs","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\nimport { SliceTemplateLibraryManager } from \"./sliceTemplateLibrary/SliceTemplateLibraryManager\";\nimport { GitManager } from \"./git/GitManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\tsliceTemplateLibrary: SliceTemplateLibraryManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\tgit: GitManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\t\tthis.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.git = new GitManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\terror instanceof prismicCustomTypesClient.UnauthorizedError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["createPrismicAuthManager","UserManager","PrismicRepositoryManager","PluginsManager","ProjectManager","CustomTypesManager","SlicesManager","SnippetsManager","ScreenshotsManager","SimulatorManager","DocumentationManager","SliceTemplateLibraryManager","VersionsManager","TelemetryManager","GitManager","API_ENDPOINTS","sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices","prismicCustomTypesClient","buildPrismicRepositoryAPIEndpoint","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkGa,oBAAmB;AAAA,EAsB/B,YAAY,MAAyC;AArB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsBA,yBAAAA;AAEtB,SAAA,OAAO,IAAIC,YAAA,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAIC,yBAAA,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAIC,eAAA,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAIC,eAAA,eAAe,IAAI;AACjC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAIC,cAAA,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AACnC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,YAAY,IAAIC,iBAAA,iBAAiB,IAAI;AACrC,SAAA,gBAAgB,IAAIC,qBAAA,qBAAqB,IAAI;AAC7C,SAAA,uBAAuB,IAAIC,4BAAA,4BAA4B,IAAI;AAE3D,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AAEnC,SAAA,YAAY,IAAIC,iBAAA,iBAAiB,IAAI;AAErC,SAAA,MAAM,IAAIC,WAAA,WAAW,IAAI;AAE9B,SAAK,OAAM,6BAAM,QAAO,QAAQ,IAAG;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,8BAA2B;AAC1B,WAAO,KAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,wBAAqB;AACpB,WAAO,KAAK;AAAA,EACb;A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AAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACvB;AAAA,MACA,CAAA,CAAC;AAAA,IAEJ;AAEO,WAAA;AAAA,EACR;AACA;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SliceMachineManager.js","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\nimport { SliceTemplateLibraryManager } from \"./sliceTemplateLibrary/SliceTemplateLibraryManager\";\nimport { GitManager } from \"./git/GitManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\tsliceTemplateLibrary: SliceTemplateLibraryManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\tgit: GitManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\t\tthis.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.git = new GitManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\terror instanceof prismicCustomTypesClient.UnauthorizedError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAkGa,oBAAmB;AAAA,EAsB/B,YAAY,MAAyC;AArB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsB;AAEtB,SAAA,OAAO,IAAI,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAI,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAI,eAAe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AC;AAGH,oBAAU,KAAK;AAAA,YACd,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA;AAAA,YACT;AAAA,YACA,MAAM;AAAA;AAAA,cAEL,cAAc;AAAA,cACd,cAAc;AAAA,cACd,UAAU;AAAA,YACV;AAAA,UAAA,CACD;AAAA,QACF;AAAA,MACA,CAAA,CAAC;AAAA,IAEJ;AAGA,WAAO,UAAU,KAAK,CAAC,UAAU,aAAY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACvB;AAAA,MACA,CAAA,CAAC;AAAA,IAEJ;AAEO,WAAA;AAAA,EACR;AACA;"}
|
1
|
+
{"version":3,"file":"SliceMachineManager.js","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import {\n\tSharedSlice,\n\tCustomType,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\nimport { DocumentationManager } from \"./documentation/DocumentationManager\";\nimport { SliceTemplateLibraryManager } from \"./sliceTemplateLibrary/SliceTemplateLibraryManager\";\nimport { GitManager } from \"./git/GitManager\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tpackageManager: PackageManager;\n\t\tendpoints: APIEndpoints;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmocks?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomType[];\n\tremoteCustomTypes: CustomType[];\n\tremoteSlices: SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\tdocumentation: DocumentationManager;\n\tsliceTemplateLibrary: SliceTemplateLibraryManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\tgit: GitManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\t\tthis.documentation = new DocumentationManager(this);\n\t\tthis.sliceTemplateLibrary = new SliceTemplateLibraryManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.git = new GitManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\terror instanceof prismicCustomTypesClient.UnauthorizedError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 403,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t\tendpoints: this.getAPIEndpoints(),\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAkGa,oBAAmB;AAAA,EAsB/B,YAAY,MAAyC;AArB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsB;AAEtB,SAAA,OAAO,IAAI,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAI,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAI,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAI,eAAe,IAAI;AACjC,SAAA,cAAc,IAAI,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAI,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAI,gBAAgB,IAAI;AACnC,SAAA,cAAc,IAAI,mBAAmB,IAAI;AACzC,SAAA,YAAY,IAAI,iBAAiB,IAAI;AACrC,SAAA,gBAAgB,IAAI,qBAAqB,IAAI;AAC7C,SAAA,uBAAuB,IAAI,4BAA4B,IAAI;AAE3D,SAAA,WAAW,IAAI,gBAAgB,IAAI;AAEnC,SAAA,YAAY,IAAI,iBAAiB,IAAI;AAErC,SAAA,MAAM,IAAI,WAAW,IAAI;AAE9B,SAAK,OAAM,6BAAM,QAAO,QAAQ,IAAG;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,8B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AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACvB;AAAA,MACA,CAAA,CAAC;AAAA,IAEJ;AAEO,WAAA;AAAA,EACR;AACA;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomTypesManager.cjs","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n\tlangSmithUrl: z.string().url().optional(),\n});\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","CustomType","prismicCustomTypesClient","API_ENDPOINTS","fetch","SLICE_MACHINE_USER_AGENT","UnauthorizedError","z","SharedSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1BC,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,QAAAC,QAAA,IAAWC,iBAAAA,iBACxBC,aAAE,KAAK;AAAA,MACN,KAAKA,aAAE,MAAMA,aAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB,QAAAF;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/CD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,QAAAC,QAAA,IAAW,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AAK,KAAK,uBAAsB;AACxD,UAAM,UAAU;AAAA,MACf,eAAe,UAAU;AAAA,IAAA;AAG1B,UAAM,aAAa,MAAM,KAAK,QAAQ,0BAAyB;AACzD,UAAA,eAAe,IAAI,gBAAgB;AAAA,MACxC;AAAA,IAAA,CACA;AAED,UAAM,MAAM,IAAI,IAAI,kBAAkBF,4BAAc,iBAAiB;AACjE,QAAA,SAAS,aAAa;AAE1B,UAAM,WAAW,MAAMC,MAAAA,QAAM,IAAI,YAAY;AAAA,MAC5C,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,UAAU;AAAA,IAAA,CACjC;AAEG,QAAA,CAAC,SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqBG,cAAE,OAAO;AAAA,EACnC,OAAOA,MAAE,QAAA,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAASC,YAAAA,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAMD,MAAAA,QAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAOA,MAAAA,QAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAcA,MAAAA,QAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;;"}
|
1
|
+
{"version":3,"file":"CustomTypesManager.cjs","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n\tlangSmithUrl: z.string().url().optional(),\n});\n"],"names":["BaseManager","assertPluginsInitialized","errors","decodeHookResult","t","Cust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,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqBG,cAAE,OAAO;AAAA,EACnC,OAAOA,MAAE,QAAA,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAASC,YAAAA,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAMD,MAAAA,QAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA,IAAA,CAChE;AAED,WAAOA,MAAAA,QAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAcA,MAAAA,QAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CustomTypesManager.js","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n\tlangSmithUrl: z.string().url().optional(),\n});\n"],"names":["errors"],"mappings":";;;;;;;;;;;AAoFM,MAAO,2BAA2B,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1B,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,MAAM,KAAK,yBAAyB,SACtD,4BACA,MAAS;AAEV,UAAM,EAAE,MAAM,OAAA,IAAW,iBACxB,EAAE,KAAK;AAAA,MACN,KAAK,EAAE,MAAM,EAAE,MAAM;AAAA,IAAA,CACrB,GACD,UAAU;AAGJ,WAAA;AAAA,MACN,OAAK,UAAK,CAAC,MAAN,mBAAS,QAAO,CAAE;AAAA,MACvB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,mBACL,MAA+C;AAE/C,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,MAAsD;AAAA,MAC3D,QAAQ,CAAE;AAAA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;AAAA,MACf,eAAe,UAAU;AAAA,IAAA;AAG1B,UAAM,aAAa,MAAM,KAAK,QAAQ,0BAAyB;AACzD,UAAA,eAAe,IAAI,gBAAgB;AAAA,MACxC;AAAA,IAAA,CACA;AAED,UAAM,MAAM,IAAI,IAAI,kBAAkB,cAAc,iBAAiB;AACjE,QAAA,SAAS,aAAa;AAE1B,UAAM,WAAW,MAAM,MAAM,IAAI,YAAY;AAAA,MAC5C,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,UAAU;AAAA,IAAA,CACjC;AAEG,QAAA,CAAC,SAAS,IAAI;AACjB,YAAM,IAAI,MAAM,0BAA0B,SAAS,YAAY;AAAA,IAChE;AAEM,UAAA,OAAO,MAAM,SAAS;AAErB,WAAA,mBAAmB,MAAM,IAAI;AAAA,EACrC;AACA;AAID,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACnC,OAAO,EAAE,OAAA,EAAS,UAAU,CAAC,OAAO,QAAO;AACpC,UAAA,SAAS,YAAY,OAAO,KAAK;AACnC,QAAA,OAAO,SAAS,SAAS;AAC5B,aAAO,OAAO;AAAA,IACf;AACA,QAAI,SAAS;AAAA,MACZ,MAAM,EAAE,aAAa;AAAA,MACrB,SAAS,yBAAyB,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IAAA,CAC/D;AAED,WAAO,EAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAc,EAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;"}
|
1
|
+
{"version":3,"file":"CustomTypesManager.js","sources":["../../../../src/managers/customTypes/CustomTypesManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as prismicCustomTypesClient from \"@prismicio/custom-types-client\";\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport {\n\tCallHookReturnType,\n\tCustomTypeCreateHook,\n\tCustomTypeCreateHookData,\n\tCustomTypeReadHookData,\n\tCustomTypeRenameHook,\n\tCustomTypeRenameHookData,\n\tCustomTypeUpdateHook,\n\tCustomTypeUpdateHookData,\n\tHookError,\n} from \"@slicemachine/plugin-kit\";\nimport { z } from \"zod\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport fetch from \"../../lib/fetch\";\n\nimport { OnlyHookErrors } from \"../../types\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { UnauthorizedError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\nimport { CustomTypeFormat } from \"./types\";\n\ntype SliceMachineManagerReadCustomTypeLibraryReturnType = {\n\tids: string[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypesManagerReadAllCustomTypesArgs = {\n\tformat: CustomTypeFormat;\n};\n\ntype SliceMachineManagerReadAllCustomTypeReturnType = {\n\tmodels: { model: CustomType }[];\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerReadCustomTypeReturnType = {\n\tmodel: CustomType | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype SliceMachineManagerPushCustomTypeArgs = {\n\tid: string;\n\tuserAgent?: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n};\n\ntype SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType = {\n\t// TODO\n\tmocksConfig?: Record<string, unknown>;\n\terrors: HookError[];\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgs = {\n\tcustomTypeID: string;\n\t// TODO\n\tmocksConfig: Record<string, unknown>;\n};\n\ntype SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType = {\n\terrors: HookError[];\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeArgs = {\n\tid: string;\n};\n\ntype CustomTypesMachineManagerDeleteCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\nexport class CustomTypesManager extends BaseManager {\n\tasync readCustomTypeLibrary(): Promise<SliceMachineManagerReadCustomTypeLibraryReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type-library:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tids: t.array(t.string),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tids: data[0]?.ids || [],\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync readAllCustomTypes(\n\t\targs?: CustomTypesManagerReadAllCustomTypesArgs,\n\t): Promise<SliceMachineManagerReadAllCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst res: SliceMachineManagerReadAllCustomTypeReturnType = {\n\t\t\tmodels: [],\n\t\t\terrors: [],\n\t\t};\n\n\t\tconst { ids, errors } = await this.readCustomTypeLibrary();\n\t\tres.errors = [...res.errors, ...errors];\n\n\t\tif (ids) {\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst { model, errors } = await this.readCustomType({ id });\n\t\t\t\tres.errors = [...res.errors, ...errors];\n\n\t\t\t\tif (model && (!args || args.format === model.format)) {\n\t\t\t\t\tres.models.push({ model });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync createCustomType(\n\t\targs: CustomTypeCreateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeCreateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:create\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync readCustomType(\n\t\targs: CustomTypeReadHookData,\n\t): Promise<SliceMachineManagerReadCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:read\",\n\t\t\targs,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tmodel: CustomType,\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\treturn {\n\t\t\tmodel: data[0]?.model,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync renameCustomType(\n\t\targs: CustomTypeRenameHookData,\n\t): Promise<OnlyHookErrors<CallHookReturnType<CustomTypeRenameHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:rename\",\n\t\t\targs,\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync deleteCustomType(\n\t\targs: CustomTypesMachineManagerDeleteCustomTypeArgs,\n\t): Promise<CustomTypesMachineManagerDeleteCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model, errors: readCustomTypeErrors } = await this.readCustomType({\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (model) {\n\t\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\t\"custom-type:delete\",\n\t\t\t\t{ model },\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\terrors: readCustomTypeErrors,\n\t\t\t};\n\t\t}\n\t}\n\n\tasync pushCustomType(\n\t\targs: SliceMachineManagerPushCustomTypeArgs,\n\t): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t// TODO: Handle errors\n\t\tconst { model } = await this.readCustomType({ id: args.id });\n\n\t\tif (model) {\n\t\t\t// TODO: Create a single shared client.\n\t\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\t\trepositoryName,\n\t\t\t\ttoken: authenticationToken,\n\t\t\t\tfetch,\n\t\t\t\tfetchOptions: {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Check if Custom Type already exists on the repository.\n\t\t\t\tawait client.getCustomTypeByID(args.id);\n\n\t\t\t\t// If it exists on the repository, update it.\n\t\t\t\tawait client.updateCustomType(model);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof prismicCustomTypesClient.NotFoundError) {\n\t\t\t\t\t// If it doesn't exist on the repository, insert it.\n\t\t\t\t\tawait client.insertCustomType(model);\n\t\t\t\t} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\"You do not have access to push types to this Prismic repository.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync readCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerReadCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerReadCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:read\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tassetID: \"mocks.config.json\",\n\t\t\t},\n\t\t);\n\t\tconst data = hookResult.data[0]?.data;\n\n\t\t// TODO: Validate the returned data.\n\n\t\tif (data) {\n\t\t\treturn {\n\t\t\t\tmocksConfig: JSON.parse(data.toString()),\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tmocksConfig: undefined,\n\t\t\t\terrors: hookResult.errors,\n\t\t\t};\n\t\t}\n\t}\n\n\t// TODO: Remove\n\tasync updateCustomTypeMocksConfig(\n\t\targs: SliceMachineManagerUpdateCustomTypeMocksConfigArgs,\n\t): Promise<SliceMachineManagerUpdateCustomTypeMocksConfigArgsReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:asset:update\",\n\t\t\t{\n\t\t\t\tcustomTypeID: args.customTypeID,\n\t\t\t\tasset: {\n\t\t\t\t\tid: \"mocks.config.json\",\n\t\t\t\t\tdata: Buffer.from(JSON.stringify(args.mocksConfig, null, \"\\t\")),\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tasync fetchRemoteCustomTypes(): Promise<CustomType[]> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\tconst client = prismicCustomTypesClient.createClient({\n\t\t\tendpoint: API_ENDPOINTS.PrismicModels,\n\t\t\trepositoryName,\n\t\t\ttoken: authenticationToken,\n\t\t\tfetch,\n\t\t\tfetchOptions: {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\treturn await client.getAllCustomTypes();\n\t}\n\n\tasync inferSlice({\n\t\timageUrl,\n\t}: {\n\t\timageUrl: string;\n\t}): Promise<InferSliceResponse> {\n\t\tconst authToken = await this.user.getAuthenticationToken();\n\t\tconst headers = {\n\t\t\tAuthorization: `Bearer ${authToken}`,\n\t\t};\n\n\t\tconst repository = await this.project.getResolvedRepositoryName();\n\t\tconst searchParams = new URLSearchParams({\n\t\t\trepository,\n\t\t});\n\n\t\tconst url = new URL(\"./slices/infer\", API_ENDPOINTS.CustomTypeService);\n\t\turl.search = searchParams.toString();\n\n\t\tconst response = await fetch(url.toString(), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: headers,\n\t\t\tbody: JSON.stringify({ imageUrl }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to infer slice: ${response.statusText}`);\n\t\t}\n\n\t\tconst json = await response.json();\n\n\t\treturn InferSliceResponse.parse(json);\n\t}\n}\n\ntype InferSliceResponse = z.infer<typeof InferSliceResponse>;\n\nconst InferSliceResponse = z.object({\n\tslice: z.custom().transform((value, ctx) => {\n\t\tconst result = SharedSlice.decode(value);\n\t\tif (result._tag === \"Right\") {\n\t\t\treturn result.right;\n\t\t}\n\t\tctx.addIssue({\n\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\tmessage: `Invalid shared slice: ${JSON.stringify(value, null, 2)}`,\n\t\t});\n\n\t\treturn z.NEVER;\n\t}),\n\tlangSmithUrl: z.string().url().optional(),\n});\n"],"names":["errors"],"mappings":";;;;;;;;;;;AAoFM,MAAO,2BAA2B,YAAW;AAAA,EAClD,MAAM,wBAAqB;;AAC1B,6BAAyB,KAAK,wBAAwB;AAEtD,UAAM,aAAa,M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AED,WAAO,EAAE;AAAA,EAAA,CACT;AAAA,EACD,cAAc,EAAE,OAAS,EAAA,IAAA,EAAM,SAAU;AACzC,CAAA;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"GitManager.cjs","sources":["../../../../src/managers/git/GitManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as tt from \"io-ts-types\";\nimport { execaCommandSync } from \"execa\";\n\nimport fetch from \"../../lib/fetch\";\nimport { decode } from \"../../lib/decode\";\n\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { GitProvider, GIT_PROVIDER } from \"../../constants/GIT_PROVIDER\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n\tUnsupportedError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport { GitOwner, GitRepo, GitRepoSpecifier } from \"./types\";\nimport { buildGitRepoSpecifier } from \"./buildGitRepoSpecifier\";\nimport { GIT_PROVIDER_APP_SLUGS } from \"../../constants/GIT_PROVIDER_APP_SLUGS\";\n\ntype GitManagerCreateGitHubAuthStateReturnType = {\n\tkey: string;\n\texpiresAt: Date;\n};\n\ntype GitManagerFetchOwnersReturnType = GitOwner[];\n\ntype GitManagerFetchReposReturnType = GitRepo[];\n\ntype GitManagerFetchReposArgs = {\n\tprovider: GitProvider;\n\towner: string;\n\tquery?: string;\n\tpage?: number;\n};\n\ntype GitManagerFetchLinkedReposArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n};\n\ntype GitManagerFetchLinkedReposReturnType = GitRepoSpecifier[];\n\ntype GitManagerLinkRepoArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\ntype GitManagerUnlinkRepoArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\ntype CheckHasWriteAPITokenArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\ntype UpdateWriteAPITokenArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n\ttoken: string;\n};\n\ntype DeleteWriteAPITokenArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\nexport class GitManager extends BaseManager {\n\tasync createGitHubAuthState(): Promise<GitManagerCreateGitHubAuthStateReturnType> {\n\t\tconst url = new URL(\n\t\t\t\"./git/github/create-auth-state\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\tconst res = await this.#fetch(url, { method: \"POST\" });\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to create GitHub auth state.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\tkey: t.string,\n\t\t\t\texpiresAt: tt.DateFromISOString,\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode GitHub auth state: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\tasync fetchOwners(): Promise<GitManagerFetchOwnersReturnType> {\n\t\tconst url = new URL(\"./git/owners\", API_ENDPOINTS.SliceMachineV1);\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to fetch owners.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\towners: t.array(\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tprovider: t.literal(GIT_PROVIDER.GitHub),\n\t\t\t\t\t\tid: t.string,\n\t\t\t\t\t\tname: t.string,\n\t\t\t\t\t\ttype: t.union([t.literal(\"user\"), t.literal(\"team\"), t.null]),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode owners: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.owners;\n\t}\n\n\tasync fetchRepos(\n\t\targs: GitManagerFetchReposArgs,\n\t): Promise<GitManagerFetchReposReturnType> {\n\t\tconst url = new URL(\"./git/repos\", API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"provider\", args.provider);\n\t\turl.searchParams.set(\"owner\", args.owner);\n\t\tif (args.query) {\n\t\t\turl.searchParams.set(\"q\", args.query);\n\t\t}\n\t\tif (args.page && args.page > 0) {\n\t\t\turl.searchParams.set(\"page\", args.page.toString());\n\t\t}\n\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to fetch repos.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\trepos: t.array(\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tprovider: t.literal(GIT_PROVIDER.GitHub),\n\t\t\t\t\t\tid: t.string,\n\t\t\t\t\t\towner: t.string,\n\t\t\t\t\t\tname: t.string,\n\t\t\t\t\t\turl: t.string,\n\t\t\t\t\t\tpushedAt: tt.DateFromISOString,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode repos: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.repos;\n\t}\n\n\tasync fetchLinkedRepos(\n\t\targs: GitManagerFetchLinkedReposArgs,\n\t): Promise<GitManagerFetchLinkedReposReturnType> {\n\t\tconst url = new URL(\"./git/linked-repos\", API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", args.prismic.domain);\n\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to fetch linked repos.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\trepos: t.array(\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tprovider: t.literal(GIT_PROVIDER.GitHub),\n\t\t\t\t\t\towner: t.string,\n\t\t\t\t\t\tname: t.string,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode linked repos: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.repos;\n\t}\n\n\tasync linkRepo(args: GitManagerLinkRepoArgs): Promise<void> {\n\t\tconst url = new URL(\"./git/linked-repos\", API_ENDPOINTS.SliceMachineV1);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"PUT\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to link repos.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync unlinkRepo(args: GitManagerUnlinkRepoArgs): Promise<void> {\n\t\tconst url = new URL(\"./git/linked-repos\", API_ENDPOINTS.SliceMachineV1);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"DELETE\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to unlink repos.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync checkHasWriteAPIToken(\n\t\targs: CheckHasWriteAPITokenArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t\"./git/linked-repos/write-api-token\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\turl.searchParams.set(\"repository\", args.prismic.domain);\n\t\turl.searchParams.set(\n\t\t\t\"git\",\n\t\t\tbuildGitRepoSpecifier({\n\t\t\t\tprovider: args.git.provider,\n\t\t\t\towner: args.git.owner,\n\t\t\t\tname: args.git.name,\n\t\t\t}),\n\t\t);\n\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to check Prismic Write API token.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\thasWriteAPIToken: t.boolean,\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.hasWriteAPIToken;\n\t}\n\n\tasync updateWriteAPIToken(args: UpdateWriteAPITokenArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./git/linked-repos/write-api-token\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"PUT\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t\ttoken: args.token,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to update Prismic Write API token.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync deleteWriteAPIToken(args: DeleteWriteAPITokenArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./git/linked-repos/write-api-token\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"DELETE\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to delete Prismic Write API token.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync getProviderAppInstallURL(args: {\n\t\tprovider: GitProvider;\n\t}): Promise<string> {\n\t\tconst appSlug = GIT_PROVIDER_APP_SLUGS[args.provider];\n\n\t\tswitch (args.provider) {\n\t\t\tcase GIT_PROVIDER.GitHub: {\n\t\t\t\tconst state = await this.createGitHubAuthState();\n\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`https://github.com/apps/${appSlug}/installations/new`,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"state\", state.key);\n\n\t\t\t\treturn url.toString();\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthrow new UnsupportedError(\n\t\t\t\t\t`Git provider not supported: ${args.provider}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync detectGitProvider(): Promise<string> {\n\t\ttry {\n\t\t\tconst remoteUrl = execaCommandSync(\"git remote get-url origin\");\n\t\t\tconst domainRegex = /(?:https?:\\/\\/|git@)([^:/]+)[/:]/i;\n\t\t\tconst match = remoteUrl.stdout.match(domainRegex);\n\t\t\tconst domain = match?.[1] ?? \"\";\n\n\t\t\treturn domain;\n\t\t} catch (error) {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tconsole.error(\"Failed to detect Git provider:\", error);\n\t\t\t}\n\n\t\t\treturn \"_unknown\";\n\t\t}\n\t}\n\n\tasync #fetch(\n\t\turl: URL,\n\t\tconfig?: {\n\t\t\tmethod?: \"POST\" | \"PUT\" | \"DELETE\";\n\t\t\tbody?: unknown;\n\t\t},\n\t) {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\n\t\treturn await fetch(url, {\n\t\t\tmethod: config?.method,\n\t\t\tbody: config?.body ? JSON.stringify(config.body) : undefined,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${authenticationToken}`,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["BaseManager","API_ENDPOINTS","UnauthorizedError","decode","t","tt","UnexpectedDataError","UnauthenticatedError","GIT_PROVIDER","buildGitRepoSpecifier","GIT_PROVIDER_APP_SLUGS","UnsupportedError","execaCommandSync","fetch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGM,MAAO,mBAAmBA,YAAAA,YAAW;AAAA,EAArC;AAAA;AA6XL,uBAAM;AAAA;AAAA,EA5XN,MAAM,wBAAqB;AAC1B,UAAM,MAAM,IAAI,IACf,kCACAC,4BAAc,cAAc;AAEvB,UAAA,MAAM,MAAM,sBAAK,kBAAL,WAAY,KAAK,EAAE,QAAQ;AAEzC,QAAA,CAAC,IAAI,IAAI;AACZ,cAAQ,IAAI,QA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AED,QAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAE3D,SAAA,MAAMC,cAAM,KAAK;AAAA,IACvB,QAAQ,iCAAQ;AAAA,IAChB,OAAM,iCAAQ,QAAO,KAAK,UAAU,OAAO,IAAI,IAAI;AAAA,IACnD,SAAS;AAAA,MACR,eAAe,UAAU;AAAA,IACzB;AAAA,EAAA,CACD;AACF;;"}
|
1
|
+
{"version":3,"file":"GitManager.cjs","sources":["../../../../src/managers/git/GitManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as tt from \"io-ts-types\";\nimport { execaCommandSync } from \"execa\";\n\nimport fetch from \"../../lib/fetch\";\nimport { decode } from \"../../lib/decode\";\n\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { GitProvider, GIT_PROVIDER } from \"../../constants/GIT_PROVIDER\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n\tUnsupportedError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport { GitOwner, GitRepo, GitRepoSpecifier } from \"./types\";\nimport { buildGitRepoSpecifier } from \"./buildGitRepoSpecifier\";\nimport { GIT_PROVIDER_APP_SLUGS } from \"../../constants/GIT_PROVIDER_APP_SLUGS\";\n\ntype GitManagerCreateGitHubAuthStateReturnType = {\n\tkey: string;\n\texpiresAt: Date;\n};\n\ntype GitManagerFetchOwnersReturnType = GitOwner[];\n\ntype GitManagerFetchReposReturnType = GitRepo[];\n\ntype GitManagerFetchReposArgs = {\n\tprovider: GitProvider;\n\towner: string;\n\tquery?: string;\n\tpage?: number;\n};\n\ntype GitManagerFetchLinkedReposArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n};\n\ntype GitManagerFetchLinkedReposReturnType = GitRepoSpecifier[];\n\ntype GitManagerLinkRepoArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\ntype GitManagerUnlinkRepoArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\ntype CheckHasWriteAPITokenArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\ntype UpdateWriteAPITokenArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n\ttoken: string;\n};\n\ntype DeleteWriteAPITokenArgs = {\n\tprismic: {\n\t\tdomain: string;\n\t};\n\tgit: {\n\t\tprovider: GitProvider;\n\t\towner: string;\n\t\tname: string;\n\t};\n};\n\nexport class GitManager extends BaseManager {\n\tasync createGitHubAuthState(): Promise<GitManagerCreateGitHubAuthStateReturnType> {\n\t\tconst url = new URL(\n\t\t\t\"./git/github/create-auth-state\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\tconst res = await this.#fetch(url, { method: \"POST\" });\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to create GitHub auth state.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\tkey: t.string,\n\t\t\t\texpiresAt: tt.DateFromISOString,\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode GitHub auth state: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\tasync fetchOwners(): Promise<GitManagerFetchOwnersReturnType> {\n\t\tconst url = new URL(\"./git/owners\", API_ENDPOINTS.SliceMachineV1);\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to fetch owners.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\towners: t.array(\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tprovider: t.literal(GIT_PROVIDER.GitHub),\n\t\t\t\t\t\tid: t.string,\n\t\t\t\t\t\tname: t.string,\n\t\t\t\t\t\ttype: t.union([t.literal(\"user\"), t.literal(\"team\"), t.null]),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode owners: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.owners;\n\t}\n\n\tasync fetchRepos(\n\t\targs: GitManagerFetchReposArgs,\n\t): Promise<GitManagerFetchReposReturnType> {\n\t\tconst url = new URL(\"./git/repos\", API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"provider\", args.provider);\n\t\turl.searchParams.set(\"owner\", args.owner);\n\t\tif (args.query) {\n\t\t\turl.searchParams.set(\"q\", args.query);\n\t\t}\n\t\tif (args.page && args.page > 0) {\n\t\t\turl.searchParams.set(\"page\", args.page.toString());\n\t\t}\n\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to fetch repos.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\trepos: t.array(\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tprovider: t.literal(GIT_PROVIDER.GitHub),\n\t\t\t\t\t\tid: t.string,\n\t\t\t\t\t\towner: t.string,\n\t\t\t\t\t\tname: t.string,\n\t\t\t\t\t\turl: t.string,\n\t\t\t\t\t\tpushedAt: tt.DateFromISOString,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode repos: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.repos;\n\t}\n\n\tasync fetchLinkedRepos(\n\t\targs: GitManagerFetchLinkedReposArgs,\n\t): Promise<GitManagerFetchLinkedReposReturnType> {\n\t\tconst url = new URL(\"./git/linked-repos\", API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", args.prismic.domain);\n\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to fetch linked repos.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\trepos: t.array(\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tprovider: t.literal(GIT_PROVIDER.GitHub),\n\t\t\t\t\t\towner: t.string,\n\t\t\t\t\t\tname: t.string,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode linked repos: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.repos;\n\t}\n\n\tasync linkRepo(args: GitManagerLinkRepoArgs): Promise<void> {\n\t\tconst url = new URL(\"./git/linked-repos\", API_ENDPOINTS.SliceMachineV1);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"PUT\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to link repos.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync unlinkRepo(args: GitManagerUnlinkRepoArgs): Promise<void> {\n\t\tconst url = new URL(\"./git/linked-repos\", API_ENDPOINTS.SliceMachineV1);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"DELETE\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to unlink repos.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync checkHasWriteAPIToken(\n\t\targs: CheckHasWriteAPITokenArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t\"./git/linked-repos/write-api-token\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\turl.searchParams.set(\"repository\", args.prismic.domain);\n\t\turl.searchParams.set(\n\t\t\t\"git\",\n\t\t\tbuildGitRepoSpecifier({\n\t\t\t\tprovider: args.git.provider,\n\t\t\t\towner: args.git.owner,\n\t\t\t\tname: args.git.name,\n\t\t\t}),\n\t\t);\n\n\t\tconst res = await this.#fetch(url);\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to check Prismic Write API token.\");\n\t\t\t}\n\t\t}\n\n\t\tconst json = await res.json();\n\t\tconst { value, error } = decode(\n\t\t\tt.type({\n\t\t\t\thasWriteAPIToken: t.boolean,\n\t\t\t}),\n\t\t\tjson,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t`Failed to decode: ${error.errors.join(\", \")}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\n\t\treturn value.hasWriteAPIToken;\n\t}\n\n\tasync updateWriteAPIToken(args: UpdateWriteAPITokenArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./git/linked-repos/write-api-token\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"PUT\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t\ttoken: args.token,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to update Prismic Write API token.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync deleteWriteAPIToken(args: DeleteWriteAPITokenArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./git/linked-repos/write-api-token\",\n\t\t\tAPI_ENDPOINTS.SliceMachineV1,\n\t\t);\n\t\tconst res = await this.#fetch(url, {\n\t\t\tmethod: \"DELETE\",\n\t\t\tbody: {\n\t\t\t\tprismic: {\n\t\t\t\t\tdomain: args.prismic.domain,\n\t\t\t\t},\n\t\t\t\tgit: {\n\t\t\t\t\tprovider: args.git.provider,\n\t\t\t\t\towner: args.git.owner,\n\t\t\t\t\tname: args.git.name,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 401:\n\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\tcase 403:\n\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Failed to delete Prismic Write API token.\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync getProviderAppInstallURL(args: {\n\t\tprovider: GitProvider;\n\t}): Promise<string> {\n\t\tconst appSlug = GIT_PROVIDER_APP_SLUGS[args.provider];\n\n\t\tswitch (args.provider) {\n\t\t\tcase GIT_PROVIDER.GitHub: {\n\t\t\t\tconst state = await this.createGitHubAuthState();\n\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`https://github.com/apps/${appSlug}/installations/new`,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"state\", state.key);\n\n\t\t\t\treturn url.toString();\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthrow new UnsupportedError(\n\t\t\t\t\t`Git provider not supported: ${args.provider}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync detectGitProvider(): Promise<string> {\n\t\ttry {\n\t\t\tconst remoteUrl = execaCommandSync(\"git remote get-url origin\");\n\t\t\tconst domainRegex = /(?:https?:\\/\\/|git@)([^:/]+)[/:]/i;\n\t\t\tconst match = remoteUrl.stdout.match(domainRegex);\n\t\t\tconst domain = match?.[1] ?? \"\";\n\n\t\t\treturn domain;\n\t\t} catch (error) {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tconsole.error(\"Failed to detect Git provider:\", error);\n\t\t\t}\n\n\t\t\treturn \"_unknown\";\n\t\t}\n\t}\n\n\tasync #fetch(\n\t\turl: URL,\n\t\tconfig?: {\n\t\t\tmethod?: \"POST\" | \"PUT\" | \"DELETE\";\n\t\t\tbody?: unknown;\n\t\t},\n\t) {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\n\t\treturn await fetch(url, {\n\t\t\tmethod: config?.method,\n\t\t\tbody: config?.body ? JSON.stringify(config.body) : undefined,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${authenticationToken}`,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["BaseManager","API_ENDPOINTS","UnauthorizedError","decode","t","tt","UnexpectedDataError","UnauthenticatedError","GIT_PROVIDER","buildGitRepoSpecifier","GIT_PROVIDER_APP_SLUGS","UnsupportedError","execaCommandSync","fetch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGM,MAAO,mBAAmBA,YAAAA,YAAW;AAAA,EAArC;AAAA;AA6XL,uBAAM;AAAA;AAAA,EA5XN,MAAM,wBAAqB;AAC1B,UAAM,MAAM,IAAI,IACf,kCACAC,4BAA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