@slicemachine/manager 0.24.15-beta.7 → 0.24.15-beta.9
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 +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 +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/index.cjs +1 -1
- package/dist/_node_modules/cross-spawn/index.js +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/_virtual/index2.cjs +3 -4
- package/dist/_virtual/index2.cjs.map +1 -1
- package/dist/_virtual/index2.js +2 -4
- package/dist/_virtual/index2.js.map +1 -1
- package/dist/_virtual/index3.cjs +4 -3
- package/dist/_virtual/index3.cjs.map +1 -1
- package/dist/_virtual/index3.js +4 -2
- package/dist/_virtual/index3.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":"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\tGroup,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\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\ntype CustomTypesMachineManagerUpdateCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypeFieldIdChangedMeta = {\n\tpreviousPath: string[];\n\tnewPath: string[];\n};\n\ntype CrCustomType =\n\t| string\n\t| { id: string; fields?: readonly CrCustomTypeNestedCr[] };\ntype CrCustomTypeNestedCr =\n\t| string\n\t| { id: string; customtypes: readonly CrCustomTypeFieldLeaf[] };\ntype CrCustomTypeFieldLeaf =\n\t| string\n\t| { id: string; fields?: readonly string[] };\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\t/**\n\t * Update the Content Relationship API IDs for all existing custom types and\n\t * slices. The change is determined by properties inside the `updateMeta`\n\t * property.\n\t */\n\tprivate async updateContentRelationships(\n\t\targs: { model: CustomType } & CustomTypeFieldIdChangedMeta,\n\t): Promise<\n\t\tOnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>> & {\n\t\t\trollback?: () => Promise<void>;\n\t\t}\n\t> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model } = args;\n\t\tlet { newPath, previousPath } = args;\n\n\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\tconst crUpdates: {\n\t\t\t\tupdatePromise: Promise<{ errors: HookError[] }>;\n\t\t\t\trollback: () => void;\n\t\t\t}[] = [];\n\n\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t// any custom type and update them to use the new one.\n\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\tupdateCustomTypeContentRelationships({\n\t\t\t\tmodels: customTypes.models,\n\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\"custom-type:update\",\n\t\t\t\t\t\t\t{ model: updatedModel },\n\t\t\t\t\t\t),\n\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\t\tmodel: previousModel,\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\tpreviousPath,\n\t\t\t\tnewPath,\n\t\t\t});\n\n\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\tfor (const library of libraries) {\n\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t});\n\n\t\t\t\tupdateSharedSliceContentRelationships({\n\t\t\t\t\tmodels: slices.models,\n\t\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\t\"slice:update\",\n\t\t\t\t\t\t\t\t{ libraryID: library.libraryID, model: updatedModel },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\t\tmodel: previousModel,\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\t\t\t\t\t},\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Process all the Content Relationship updates at once.\n\t\t\tconst crUpdatesResult = await Promise.all(\n\t\t\t\tcrUpdates.map((update) => update.updatePromise),\n\t\t\t);\n\n\t\t\tif (crUpdatesResult.some((result) => result.errors.length > 0)) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: crUpdatesResult.flatMap((result) => result.errors),\n\t\t\t\t\trollback: async () => {\n\t\t\t\t\t\tawait Promise.all(crUpdates.map((update) => update.rollback()));\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<CustomTypesMachineManagerUpdateCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\t\tconst { model } = args;\n\t\tconst { fieldIdChanged } = args.updateMeta ?? {};\n\n\t\tlet previousCustomType: CustomType | undefined;\n\n\t\tif (fieldIdChanged) {\n\t\t\tconst customTypeRead = await this.readCustomType({ id: model.id });\n\n\t\t\tif (customTypeRead.errors.length > 0) {\n\t\t\t\treturn { errors: customTypeRead.errors };\n\t\t\t}\n\t\t\tif (!customTypeRead.model) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`readCustomType succeeded reading custom type ${model.id} but model is undefined.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpreviousCustomType = customTypeRead.model;\n\t\t}\n\n\t\tconst customTypeUpdateResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\t{ model },\n\t\t);\n\n\t\tif (customTypeUpdateResult.errors.length > 0) {\n\t\t\treturn { errors: customTypeUpdateResult.errors };\n\t\t}\n\n\t\tif (previousCustomType && fieldIdChanged) {\n\t\t\tconst crUpdateResult = await this.updateContentRelationships({\n\t\t\t\t...fieldIdChanged,\n\t\t\t\tmodel: previousCustomType,\n\t\t\t});\n\n\t\t\tif (crUpdateResult.errors.length > 0) {\n\t\t\t\t// put the previous custom type back\n\t\t\t\tawait this.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\tmodel: previousCustomType,\n\t\t\t\t});\n\t\t\t\t// revert the content relationships updates\n\t\t\t\tawait crUpdateResult.rollback?.();\n\n\t\t\t\treturn { errors: crUpdateResult.errors };\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\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\nfunction updateCRCustomType(\n\targs: { customType: CrCustomType } & CustomTypeFieldIdChangedMeta,\n): CrCustomType {\n\tconst [previousCustomTypeId, previousFieldId] = args.previousPath;\n\tconst [newCustomTypeId, newFieldId] = args.newPath;\n\n\tif (!previousCustomTypeId || !newCustomTypeId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a customtype id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tif (!previousFieldId || !newFieldId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a field id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tconst customType = shallowCloneIfObject(args.customType);\n\n\tif (typeof customType === \"string\" || !customType.fields) {\n\t\treturn customType;\n\t}\n\n\tconst matchedCustomTypeId = customType.id === previousCustomTypeId;\n\n\tconst newFields = customType.fields.map((fieldArg) => {\n\t\tconst customTypeField = shallowCloneIfObject(fieldArg);\n\n\t\tif (typeof customTypeField === \"string\") {\n\t\t\tif (\n\t\t\t\tmatchedCustomTypeId &&\n\t\t\t\tcustomTypeField === previousFieldId &&\n\t\t\t\tcustomTypeField !== newFieldId\n\t\t\t) {\n\t\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t\t// so we update it new one. The field is a string, so return the new\n\t\t\t\t// id.\n\t\t\t\treturn newFieldId;\n\t\t\t}\n\n\t\t\treturn customTypeField;\n\t\t}\n\n\t\tif (\n\t\t\tmatchedCustomTypeId &&\n\t\t\tcustomTypeField.id === previousFieldId &&\n\t\t\tcustomTypeField.id !== newFieldId\n\t\t) {\n\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t// so we update it new one.\n\t\t\t// Since field is not a string, we don't exit, as we might have\n\t\t\t// something to update further down in customtypes.\n\t\t\tcustomTypeField.id = newFieldId;\n\t\t}\n\n\t\treturn {\n\t\t\t...customTypeField,\n\t\t\tcustomtypes: customTypeField.customtypes.map((customTypeArg) => {\n\t\t\t\tconst nestedCustomType = shallowCloneIfObject(customTypeArg);\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof nestedCustomType === \"string\" ||\n\t\t\t\t\t!nestedCustomType.fields ||\n\t\t\t\t\t// Since we are on the last level, if we don't start matching right\n\t\t\t\t\t// at the custom type id, we can return exit early because it's not\n\t\t\t\t\t// a match.\n\t\t\t\t\tnestedCustomType.id !== previousCustomTypeId\n\t\t\t\t) {\n\t\t\t\t\treturn nestedCustomType;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...nestedCustomType,\n\t\t\t\t\tfields: nestedCustomType.fields.map((fieldArg) => {\n\t\t\t\t\t\tconst nestedCustomTypeField = shallowCloneIfObject(fieldArg);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnestedCustomTypeField === previousFieldId &&\n\t\t\t\t\t\t\tnestedCustomTypeField !== newFieldId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Matches the previous id, so we update it and return because\n\t\t\t\t\t\t\t// it's the last level.\n\t\t\t\t\t\t\treturn newFieldId;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nestedCustomTypeField;\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n\n\treturn { ...customType, fields: newFields };\n}\n\n/**\n * Update the Content Relationship API IDs of a single field. The change is\n * determined by the `previousPath` and `newPath` properties.\n */\nfunction updateFieldContentRelationships<\n\tT extends UID | NestableWidget | Group | NestedGroup,\n>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\tconst { field, ...updateMeta } = args;\n\tif (\n\t\tfield.type !== \"Link\" ||\n\t\tfield.config?.select !== \"document\" ||\n\t\t!field.config?.customtypes\n\t) {\n\t\t// not a content relationship field\n\t\treturn field;\n\t}\n\n\tconst newCustomTypes = field.config.customtypes.map((customType) => {\n\t\treturn updateCRCustomType({ customType, ...updateMeta });\n\t});\n\n\treturn {\n\t\t...field,\n\t\tconfig: { ...field.config, customtypes: newCustomTypes },\n\t};\n}\n\nexport function updateCustomTypeContentRelationships(\n\targs: {\n\t\tmodels: { model: CustomType }[];\n\t\tonUpdate: (model: { previousModel: CustomType; model: CustomType }) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: customType } of models) {\n\t\tconst updatedCustomType = traverseCustomType({\n\t\t\tcustomType,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(customType, updatedCustomType)) {\n\t\t\tonUpdate({ model: updatedCustomType, previousModel: customType });\n\t\t}\n\t}\n}\n\nexport function updateSharedSliceContentRelationships(\n\targs: {\n\t\tmodels: { model: SharedSlice }[];\n\t\tonUpdate: (model: {\n\t\t\tpreviousModel: SharedSlice;\n\t\t\tmodel: SharedSlice;\n\t\t}) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: slice } of models) {\n\t\tconst updateSlice = traverseSharedSlice({\n\t\t\tpath: [\".\"],\n\t\t\tslice,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(slice, updateSlice)) {\n\t\t\tonUpdate({ model: updateSlice, previousModel: slice });\n\t\t}\n\t}\n}\n\nfunction isEqualModel<T extends CustomType | SharedSlice>(\n\tmodelA: T,\n\tmodelB: T,\n): boolean {\n\treturn JSON.stringify(modelA) === JSON.stringify(modelB);\n}\n\nfunction shallowCloneIfObject<T>(value: T): T {\n\tif (typeof value === \"object\") {\n\t\treturn { ...value };\n\t}\n\n\treturn value;\n}\n"],"names":["errors","_a","fieldArg"],"mappings":";;;;;;;;;;;AA6GM,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,MACV,QAAQ,CAAE;AAAA,IAAA;AAGX,UAAM,EAAE,KAAK,OAAA,IAAW,MAAM,KAAK,sBAAqB;AACxD,QAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAG,MAAM;AAEtC,QAAI,KAAK;AACR,iBAAW,MAAM,KAAK;AACf,cAAA,EAAE,OAAO,QAAAA,YAAW,MAAM,KAAK,eAAe,EAAE,GAAA,CAAI;AAC1D,YAAI,SAAS,CAAC,GAAG,IAAI,QAAQ,GAAGA,OAAM;AA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AW,EAAE,OAAO,WAAY,KAAI,QAAQ;AAC3C,UAAM,oBAAoB,mBAAmB;AAAA,MAC5C;AAAA,MACA,SAAS,CAAC,EAAE,YAAW;AACtB,eAAO,gCAAgC;AAAA,UACtC;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA,CACA;AAED,QAAI,CAAC,aAAa,YAAY,iBAAiB,GAAG;AACjD,eAAS,EAAE,OAAO,mBAAmB,eAAe,WAAY,CAAA;AAAA,IACjE;AAAA,EACD;AACD;AAEM,SAAU,sCACf,MAMgC;AAEhC,QAAM,EAAE,QAAQ,cAAc,SAAS,aAAa;AAEpD,aAAW,EAAE,OAAO,MAAO,KAAI,QAAQ;AACtC,UAAM,cAAc,oBAAoB;AAAA,MACvC,MAAM,CAAC,GAAG;AAAA,MACV;AAAA,MACA,SAAS,CAAC,EAAE,YAAW;AACtB,eAAO,gCAAgC;AAAA,UACtC;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA,CACA;AAED,QAAI,CAAC,aAAa,OAAO,WAAW,GAAG;AACtC,eAAS,EAAE,OAAO,aAAa,eAAe,MAAO,CAAA;AAAA,IACtD;AAAA,EACD;AACD;AAEA,SAAS,aACR,QACA,QAAS;AAET,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,UAAU,MAAM;AACxD;AAEA,SAAS,qBAAwB,OAAQ;AACpC,MAAA,OAAO,UAAU,UAAU;AACvB,WAAA,EAAE,GAAG;EACb;AAEO,SAAA;AACR;"}
|
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\tGroup,\n\tNestableWidget,\n\tNestedGroup,\n\tSharedSlice,\n\tUID,\n\ttraverseCustomType,\n\ttraverseSharedSlice,\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\ntype CustomTypesMachineManagerUpdateCustomTypeReturnType = {\n\terrors: (DecodeError | HookError)[];\n};\n\ntype CustomTypeFieldIdChangedMeta = {\n\tpreviousPath: string[];\n\tnewPath: string[];\n};\n\ntype CrCustomType =\n\t| string\n\t| { id: string; fields?: readonly CrCustomTypeNestedCr[] };\ntype CrCustomTypeNestedCr =\n\t| string\n\t| { id: string; customtypes: readonly CrCustomTypeFieldLeaf[] };\ntype CrCustomTypeFieldLeaf =\n\t| string\n\t| { id: string; fields?: readonly string[] };\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\t/**\n\t * Update the Content Relationship API IDs for all existing custom types and\n\t * slices. The change is determined by properties inside the `updateMeta`\n\t * property.\n\t */\n\tprivate async updateContentRelationships(\n\t\targs: { model: CustomType } & CustomTypeFieldIdChangedMeta,\n\t): Promise<\n\t\tOnlyHookErrors<CallHookReturnType<CustomTypeUpdateHook>> & {\n\t\t\trollback?: () => Promise<void>;\n\t\t}\n\t> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst { model } = args;\n\t\tlet { newPath, previousPath } = args;\n\n\t\tif (previousPath.join(\".\") !== newPath.join(\".\")) {\n\t\t\tpreviousPath = [model.id, ...previousPath];\n\t\t\tnewPath = [model.id, ...newPath];\n\n\t\t\tconst crUpdates: {\n\t\t\t\tupdatePromise: Promise<{ errors: HookError[] }>;\n\t\t\t\trollback: () => void;\n\t\t\t}[] = [];\n\n\t\t\t// Find existing content relationships that link to the renamed field id in\n\t\t\t// any custom type and update them to use the new one.\n\t\t\tconst customTypes = await this.readAllCustomTypes();\n\n\t\t\tupdateCustomTypeContentRelationships({\n\t\t\t\tmodels: customTypes.models,\n\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\"custom-type:update\",\n\t\t\t\t\t\t\t{ model: updatedModel },\n\t\t\t\t\t\t),\n\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\t\t\t\tmodel: previousModel,\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\tpreviousPath,\n\t\t\t\tnewPath,\n\t\t\t});\n\n\t\t\t// Find existing slice with content relationships that link to the renamed\n\t\t\t// field id in all libraries and update them to use the new one.\n\t\t\tconst { libraries } = await this.slices.readAllSliceLibraries();\n\n\t\t\tfor (const library of libraries) {\n\t\t\t\tconst slices = await this.slices.readAllSlicesForLibrary({\n\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t});\n\n\t\t\t\tupdateSharedSliceContentRelationships({\n\t\t\t\t\tmodels: slices.models,\n\t\t\t\t\tonUpdate: ({ previousModel, model: updatedModel }) => {\n\t\t\t\t\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t\t\t\t\tcrUpdates.push({\n\t\t\t\t\t\t\tupdatePromise: this.sliceMachinePluginRunner?.callHook(\n\t\t\t\t\t\t\t\t\"slice:update\",\n\t\t\t\t\t\t\t\t{ libraryID: library.libraryID, model: updatedModel },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\trollback: () => {\n\t\t\t\t\t\t\t\tthis.sliceMachinePluginRunner?.callHook(\"slice:update\", {\n\t\t\t\t\t\t\t\t\tlibraryID: library.libraryID,\n\t\t\t\t\t\t\t\t\tmodel: previousModel,\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\t\t\t\t\t},\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Process all the Content Relationship updates at once.\n\t\t\tconst crUpdatesResult = await Promise.all(\n\t\t\t\tcrUpdates.map((update) => update.updatePromise),\n\t\t\t);\n\n\t\t\tif (crUpdatesResult.some((result) => result.errors.length > 0)) {\n\t\t\t\treturn {\n\t\t\t\t\terrors: crUpdatesResult.flatMap((result) => result.errors),\n\t\t\t\t\trollback: async () => {\n\t\t\t\t\t\tawait Promise.all(crUpdates.map((update) => update.rollback()));\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\n\t}\n\n\tasync updateCustomType(\n\t\targs: CustomTypeUpdateHookData,\n\t): Promise<CustomTypesMachineManagerUpdateCustomTypeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\t\tconst { model } = args;\n\t\tconst { fieldIdChanged } = args.updateMeta ?? {};\n\n\t\tlet previousCustomType: CustomType | undefined;\n\n\t\tif (fieldIdChanged) {\n\t\t\tconst customTypeRead = await this.readCustomType({ id: model.id });\n\n\t\t\tif (customTypeRead.errors.length > 0) {\n\t\t\t\treturn { errors: customTypeRead.errors };\n\t\t\t}\n\t\t\tif (!customTypeRead.model) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`readCustomType succeeded reading custom type ${model.id} but model is undefined.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpreviousCustomType = customTypeRead.model;\n\t\t}\n\n\t\tconst customTypeUpdateResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"custom-type:update\",\n\t\t\t{ model },\n\t\t);\n\n\t\tif (customTypeUpdateResult.errors.length > 0) {\n\t\t\treturn { errors: customTypeUpdateResult.errors };\n\t\t}\n\n\t\tif (previousCustomType && fieldIdChanged) {\n\t\t\tconst crUpdateResult = await this.updateContentRelationships({\n\t\t\t\t...fieldIdChanged,\n\t\t\t\tmodel: previousCustomType,\n\t\t\t});\n\n\t\t\tif (crUpdateResult.errors.length > 0) {\n\t\t\t\t// put the previous custom type back\n\t\t\t\tawait this.sliceMachinePluginRunner?.callHook(\"custom-type:update\", {\n\t\t\t\t\tmodel: previousCustomType,\n\t\t\t\t});\n\t\t\t\t// revert the content relationships updates\n\t\t\t\tawait crUpdateResult.rollback?.();\n\n\t\t\t\treturn { errors: crUpdateResult.errors };\n\t\t\t}\n\t\t}\n\n\t\treturn { errors: [] };\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\nfunction updateCRCustomType(\n\targs: { customType: CrCustomType } & CustomTypeFieldIdChangedMeta,\n): CrCustomType {\n\tconst [previousCustomTypeId, previousFieldId] = args.previousPath;\n\tconst [newCustomTypeId, newFieldId] = args.newPath;\n\n\tif (!previousCustomTypeId || !newCustomTypeId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a customtype id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tif (!previousFieldId || !newFieldId) {\n\t\tthrow new Error(\n\t\t\t\"Could not find a field id in previousPath and/or newPath, which should not be possible.\",\n\t\t);\n\t}\n\n\tconst customType = shallowCloneIfObject(args.customType);\n\n\tif (typeof customType === \"string\" || !customType.fields) {\n\t\treturn customType;\n\t}\n\n\tconst matchedCustomTypeId = customType.id === previousCustomTypeId;\n\n\tconst newFields = customType.fields.map((fieldArg) => {\n\t\tconst customTypeField = shallowCloneIfObject(fieldArg);\n\n\t\tif (typeof customTypeField === \"string\") {\n\t\t\tif (\n\t\t\t\tmatchedCustomTypeId &&\n\t\t\t\tcustomTypeField === previousFieldId &&\n\t\t\t\tcustomTypeField !== newFieldId\n\t\t\t) {\n\t\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t\t// so we update it new one. The field is a string, so return the new\n\t\t\t\t// id.\n\t\t\t\treturn newFieldId;\n\t\t\t}\n\n\t\t\treturn customTypeField;\n\t\t}\n\n\t\tif (\n\t\t\tmatchedCustomTypeId &&\n\t\t\tcustomTypeField.id === previousFieldId &&\n\t\t\tcustomTypeField.id !== newFieldId\n\t\t) {\n\t\t\t// We have reached a field id that matches the id that was renamed,\n\t\t\t// so we update it new one.\n\t\t\t// Since field is not a string, we don't exit, as we might have\n\t\t\t// something to update further down in customtypes.\n\t\t\tcustomTypeField.id = newFieldId;\n\t\t}\n\n\t\treturn {\n\t\t\t...customTypeField,\n\t\t\tcustomtypes: customTypeField.customtypes.map((customTypeArg) => {\n\t\t\t\tconst nestedCustomType = shallowCloneIfObject(customTypeArg);\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof nestedCustomType === \"string\" ||\n\t\t\t\t\t!nestedCustomType.fields ||\n\t\t\t\t\t// Since we are on the last level, if we don't start matching right\n\t\t\t\t\t// at the custom type id, we can return exit early because it's not\n\t\t\t\t\t// a match.\n\t\t\t\t\tnestedCustomType.id !== previousCustomTypeId\n\t\t\t\t) {\n\t\t\t\t\treturn nestedCustomType;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...nestedCustomType,\n\t\t\t\t\tfields: nestedCustomType.fields.map((fieldArg) => {\n\t\t\t\t\t\tconst nestedCustomTypeField = shallowCloneIfObject(fieldArg);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnestedCustomTypeField === previousFieldId &&\n\t\t\t\t\t\t\tnestedCustomTypeField !== newFieldId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Matches the previous id, so we update it and return because\n\t\t\t\t\t\t\t// it's the last level.\n\t\t\t\t\t\t\treturn newFieldId;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nestedCustomTypeField;\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n\n\treturn { ...customType, fields: newFields };\n}\n\n/**\n * Update the Content Relationship API IDs of a single field. The change is\n * determined by the `previousPath` and `newPath` properties.\n */\nfunction updateFieldContentRelationships<\n\tT extends UID | NestableWidget | Group | NestedGroup,\n>(args: { field: T } & CustomTypeFieldIdChangedMeta): T {\n\tconst { field, ...updateMeta } = args;\n\tif (\n\t\tfield.type !== \"Link\" ||\n\t\tfield.config?.select !== \"document\" ||\n\t\t!field.config?.customtypes\n\t) {\n\t\t// not a content relationship field\n\t\treturn field;\n\t}\n\n\tconst newCustomTypes = field.config.customtypes.map((customType) => {\n\t\treturn updateCRCustomType({ customType, ...updateMeta });\n\t});\n\n\treturn {\n\t\t...field,\n\t\tconfig: { ...field.config, customtypes: newCustomTypes },\n\t};\n}\n\nexport function updateCustomTypeContentRelationships(\n\targs: {\n\t\tmodels: { model: CustomType }[];\n\t\tonUpdate: (model: { previousModel: CustomType; model: CustomType }) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: customType } of models) {\n\t\tconst updatedCustomType = traverseCustomType({\n\t\t\tcustomType,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(customType, updatedCustomType)) {\n\t\t\tonUpdate({ model: updatedCustomType, previousModel: customType });\n\t\t}\n\t}\n}\n\nexport function updateSharedSliceContentRelationships(\n\targs: {\n\t\tmodels: { model: SharedSlice }[];\n\t\tonUpdate: (model: {\n\t\t\tpreviousModel: SharedSlice;\n\t\t\tmodel: SharedSlice;\n\t\t}) => void;\n\t} & CustomTypeFieldIdChangedMeta,\n): void {\n\tconst { models, previousPath, newPath, onUpdate } = args;\n\n\tfor (const { model: slice } of models) {\n\t\tconst updateSlice = traverseSharedSlice({\n\t\t\tpath: [\".\"],\n\t\t\tslice,\n\t\t\tonField: ({ field }) => {\n\t\t\t\treturn updateFieldContentRelationships({\n\t\t\t\t\tfield,\n\t\t\t\t\tpreviousPath,\n\t\t\t\t\tnewPath,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tif (!isEqualModel(slice, updateSlice)) {\n\t\t\tonUpdate({ model: updateSlice, previousModel: slice });\n\t\t}\n\t}\n}\n\nfunction isEqualModel<T extends CustomType | SharedSlice>(\n\tmodelA: T,\n\tmodelB: T,\n): boolean {\n\treturn JSON.stringify(modelA) === JSON.stringify(modelB);\n}\n\nfunction shallowCloneIfObject<T>(value: T): T {\n\tif (typeof value === \"object\") {\n\t\treturn { ...value };\n\t}\n\n\treturn value;\n}\n"],"names":["errors","_a","fieldArg"],"mappings":";;;;;;;;;;;AA6GM,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,KA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AA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA,CACA;AAED,QAAI,CAAC,aAAa,OAAO,WAAW,GAAG;AACtC,eAAS,EAAE,OAAO,aAAa,eAAe,MAAO,CAAA;AAAA,IACtD;AAAA,EACD;AACD;AAEA,SAAS,aACR,QACA,QAAS;AAET,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,UAAU,MAAM;AACxD;AAEA,SAAS,qBAAwB,OAAQ;AACpC,MAAA,OAAO,UAAU,UAAU;AACvB,WAAA,EAAE,GAAG;EACb;AAEO,SAAA;AACR;"}
|
@@ -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,M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EA,MAAM,oBAAiB;AAClB,QAAA;AACG,YAAA,YAAYC,uBAAiB,2BAA2B;AAC9D,YAAM,cAAc;AACpB,YAAM,QAAQ,UAAU,OAAO,MAAM,WAAW;AAC1C,YAAA,UAAS,+BAAQ,OAAM;AAEtB,aAAA;AAAA,aACC;AAKD,aAAA;AAAA,IACR;AAAA,EACD;AAmBA;AAjBM;AAAA,WACL,eAAA,KACA,QAGC;AAED,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","buildGitRep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,SAAS,MAAM,GAAG;AAEvC,eAAO,IAAI;MACZ;AAAA,MAEA,SAAS;AACR,cAAM,IAAIG,OAAA,iBACT,+BAA+B,KAAK,QAAQ,GAAG;AAAA,MAEjD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,oBAAiB;AAClB,QAAA;AACG,YAAA,YAAYC,uBAAiB,2BAA2B;AAC9D,YAAM,cAAc;AACpB,YAAM,QAAQ,UAAU,OAAO,MAAM,WAAW;AAC1C,YAAA,UAAS,+BAAQ,OAAM;AAEtB,aAAA;AAAA,aACC,OAAO;AAKR,aAAA;AAAA,IACR;AAAA,EACD;AAmBA;AAjBM;AAAA,WACL,eAAA,KACA,QAGC;AAED,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,mBAAmB;AAAA,IAC5C;AAAA,EAAA,CACD;AACF;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"GitManager.js","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 ? J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A,aACC;AAKD,aAAA;AAAA,IACR;AAAA,EACD;AAmBA;AAjBM;AAAA,WACL,eAAA,KACA,QAGC;AAED,QAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAE3D,SAAA,MAAM,MAAM,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.js","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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuGM,MAAO,mBAAmB,YAAW;AAAA,EAArC;AAAA;AA6XL,uBAAM;AAAA;AAAA,EA5XN,MAAM,wBAAqB;AAC1B,UAAM,MAAM,IAAI,IACf,kCACA,cAAc,cAAc;AAEvB,UAAA,MAAM,MAAM,sBAAK,kBAAL,WAAY,KAAK,EAAE,QAAQ;AAEzC,QAAA,CAAC,IAAI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}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildGitRepoSpecifier.cjs","sources":["../../../../src/managers/git/buildGitRepoSpecifier.ts"],"sourcesContent":["import { GitRepoSpecifier } from \"./types\";\n\n/**\n * Builds a Git repository specifier from its individual parts.\n *\n * @example\n *\n * ```typescript\n * buildGitRepoSpecifier({\n * \tprovider: \"gitHub\",\n * \towner: \"foo\",\n * \tname: \"bar\",\n * });\n * ```\n *\n * @param repoSpecifier - The Git repository specifier.\n *\n * @returns The specifier in the form of `provider@owner/name`.\n */\nexport const buildGitRepoSpecifier = (\n\trepoSpecifier: GitRepoSpecifier,\n): string => {\n\treturn `${repoSpecifier.provider}@${repoSpecifier.owner}/${repoSpecifier.name}`;\n};\n"],"names":[],"mappings":";;AAmBa,MAAA,wBAAwB,CACpC,kBACW;
|
1
|
+
{"version":3,"file":"buildGitRepoSpecifier.cjs","sources":["../../../../src/managers/git/buildGitRepoSpecifier.ts"],"sourcesContent":["import { GitRepoSpecifier } from \"./types\";\n\n/**\n * Builds a Git repository specifier from its individual parts.\n *\n * @example\n *\n * ```typescript\n * buildGitRepoSpecifier({\n * \tprovider: \"gitHub\",\n * \towner: \"foo\",\n * \tname: \"bar\",\n * });\n * ```\n *\n * @param repoSpecifier - The Git repository specifier.\n *\n * @returns The specifier in the form of `provider@owner/name`.\n */\nexport const buildGitRepoSpecifier = (\n\trepoSpecifier: GitRepoSpecifier,\n): string => {\n\treturn `${repoSpecifier.provider}@${repoSpecifier.owner}/${repoSpecifier.name}`;\n};\n"],"names":[],"mappings":";;AAmBa,MAAA,wBAAwB,CACpC,kBACW;AACJ,SAAA,GAAG,cAAc,QAAQ,IAAI,cAAc,KAAK,IAAI,cAAc,IAAI;AAC9E;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildGitRepoSpecifier.js","sources":["../../../../src/managers/git/buildGitRepoSpecifier.ts"],"sourcesContent":["import { GitRepoSpecifier } from \"./types\";\n\n/**\n * Builds a Git repository specifier from its individual parts.\n *\n * @example\n *\n * ```typescript\n * buildGitRepoSpecifier({\n * \tprovider: \"gitHub\",\n * \towner: \"foo\",\n * \tname: \"bar\",\n * });\n * ```\n *\n * @param repoSpecifier - The Git repository specifier.\n *\n * @returns The specifier in the form of `provider@owner/name`.\n */\nexport const buildGitRepoSpecifier = (\n\trepoSpecifier: GitRepoSpecifier,\n): string => {\n\treturn `${repoSpecifier.provider}@${repoSpecifier.owner}/${repoSpecifier.name}`;\n};\n"],"names":[],"mappings":"AAmBa,MAAA,wBAAwB,CACpC,kBACW;
|
1
|
+
{"version":3,"file":"buildGitRepoSpecifier.js","sources":["../../../../src/managers/git/buildGitRepoSpecifier.ts"],"sourcesContent":["import { GitRepoSpecifier } from \"./types\";\n\n/**\n * Builds a Git repository specifier from its individual parts.\n *\n * @example\n *\n * ```typescript\n * buildGitRepoSpecifier({\n * \tprovider: \"gitHub\",\n * \towner: \"foo\",\n * \tname: \"bar\",\n * });\n * ```\n *\n * @param repoSpecifier - The Git repository specifier.\n *\n * @returns The specifier in the form of `provider@owner/name`.\n */\nexport const buildGitRepoSpecifier = (\n\trepoSpecifier: GitRepoSpecifier,\n): string => {\n\treturn `${repoSpecifier.provider}@${repoSpecifier.owner}/${repoSpecifier.name}`;\n};\n"],"names":[],"mappings":"AAmBa,MAAA,wBAAwB,CACpC,kBACW;AACJ,SAAA,GAAG,cAAc,QAAQ,IAAI,cAAc,KAAK,IAAI,cAAc,IAAI;AAC9E;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PrismicRepositoryManager.cjs","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { z } from \"zod\";\nimport fetch, { Response } from \"../../lib/fetch\";\nimport { fold } from \"fp-ts/Either\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decode } from \"../../lib/decode\";\nimport { serializeCookies } from \"../../lib/serializeCookies\";\n\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { REPOSITORY_NAME_VALIDATION } from \"../../constants/REPOSITORY_NAME_VALIDATION\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tPushBody,\n\tChangeTypes,\n\tClientError,\n\tPushChangesLimit,\n\tPushChangesLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tPushChangesRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n\tFrameworkWroomTelemetryID,\n\tStarterId,\n\tEnvironment,\n\tOnboardingState,\n} from \"./types\";\nimport { sortEnvironments } from \"./sortEnvironments\";\n\nconst DEFAULT_REPOSITORY_SETTINGS = {\n\tplan: \"personal\",\n\tisAnnual: \"false\",\n\trole: \"developer\",\n};\n\ntype PrismicRepositoryManagerCheckExistsArgs = {\n\tdomain: string;\n};\n\ntype PrismicRepositoryManagerCreateArgs = {\n\tdomain: string;\n\tframework: FrameworkWroomTelemetryID;\n\tstarterId?: StarterId;\n};\n\ntype PrismicRepositoryManagerDeleteArgs = {\n\tdomain: string;\n\tpassword: string;\n};\n\ntype PrismicRepositoryManagerPushDocumentsArgs = {\n\tdomain: string;\n\tsignature: string;\n\tdocuments: Record<string, unknown>; // TODO: Type unknown if possible(?)\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsArgs = {\n\t/**\n\t * If set to `true`, all environments are returned regardless of the user's\n\t * permission level.\n\t *\n\t * If set to `false`, only environments the user can access are returned.\n\t *\n\t * @defaultValue `false`\n\t */\n\tincludeAll?: boolean;\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsReturnType = {\n\tenvironments?: Environment[];\n};\n\nexport class PrismicRepositoryManager extends BaseManager {\n\t// TODO: Add methods for repository-specific actions. E.g. creating a\n\t// new repository.\n\n\tasync readAll(): Promise<PrismicRepository[]> {\n\t\tconst url = new URL(\"./repositories\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value: repositories, error } = decode(\n\t\t\t\tt.array(PrismicRepository),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to decode repositories: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn repositories;\n\t\t} else {\n\t\t\tconst text = await res.text();\n\t\t\tthrow new Error(`Failed to read repositories`, { cause: text });\n\t\t}\n\t}\n\n\t// Should this be in manager? It's one of the few sync method\n\t//\n\t// Reply from Angelo 2022-12-22: I think it should be in manager\n\t// because we shouldn't be exporting root-level utilities from this\n\t// package. If we want to make it more inline with the other methods,\n\t// we could simplify the API by changing its signature to the\n\t// following:\n\t//\n\t// ```ts\n\t// (repositoryName: string) => Promise<boolean>\n\t// ```\n\t//\n\t// This method would:\n\t//\n\t// 1. Fetch the list of repositories for the user using `readAll()`.\n\t// The list would be cached.\n\t// 2. Determine if the user has write access to the given repository.\n\t//\n\t// This version has the following benefits:\n\t//\n\t// - Does not expect the consumer to supply a repository object; it\n\t// only requires a repository name, which could be sourced from\n\t// anything (incl. the project's `slicemachine.config.json`).\n\t//\n\t// - Similarly, it does not expect the consumer to call `readAll()`\n\t// before calling this method.\n\t//\n\t// - Works for repositories that the user does not have access to. For\n\t// example, I could use it to check if I have access to \"qwerty\",\n\t// even if I am not added as a user. The purpose of the method is\n\t// still valid: do I have write access to a given repository?\n\thasWriteAccess(repository: PrismicRepository): boolean {\n\t\tswitch (repository.role) {\n\t\t\tcase PrismicRepositoryRole.SuperUser:\n\t\t\tcase PrismicRepositoryRole.Owner:\n\t\t\tcase PrismicRepositoryRole.Administrator:\n\t\t\t\treturn true;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync checkExists(\n\t\targs: PrismicRepositoryManagerCheckExistsArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t`./app/dashboard/repositories/${args.domain}/exists`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tskipAuthentication: true,\n\t\t});\n\n\t\tconst text = await res.text();\n\n\t\tif (res.ok) {\n\t\t\treturn text === \"false\"; // Endpoint returns `false` when repository exists\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to check repository existence for domain \\`${args.domain}\\``,\n\t\t\t\t{ cause: text },\n\t\t\t);\n\t\t}\n\t}\n\n\tasync create(args: PrismicRepositoryManagerCreateArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./authentication/newrepository?app=slicemachine\",\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\n\t\tconst body = {\n\t\t\t...DEFAULT_REPOSITORY_SETTINGS,\n\t\t\tdomain: args.domain,\n\t\t\t// These properties are optional in the API but needed for tracking\n\t\t\tframework: args.framework,\n\t\t\tstarterId: args.starterId,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.SliceMachine, // Custom User Agent is required\n\t\t});\n\t\tconst text = await res.text();\n\n\t\t// Endpoint returns repository name on success, that should be within the validation range\n\t\t// Even when there is an error, we get a 200 success and so we have to check the name thanks to that\n\t\tif (\n\t\t\t!res.ok ||\n\t\t\ttext.length < REPOSITORY_NAME_VALIDATION.Min ||\n\t\t\ttext.length > REPOSITORY_NAME_VALIDATION.Max\n\t\t) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: text,\n\t\t\t});\n\t\t}\n\t}\n\n\t// TODO: Delete this endpoint? It doesn't seem to be used (I might be wrong). - Angelo\n\tasync delete(args: PrismicRepositoryManagerDeleteArgs): Promise<void> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\n\n\t\tconst url = new URL(\n\t\t\t`./app/settings/delete?_=${cookies[\"X_XSRF\"]}`, // TODO: Maybe we want to throw early if the token is no available, or get the token another way\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tconfirm: args.domain,\n\t\t\tpassword: args.password,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`Failed to delete repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync pushDocuments(\n\t\targs: PrismicRepositoryManagerPushDocumentsArgs,\n\t): Promise<void> {\n\t\tconst url = new URL(\"./starter/documents\", API_ENDPOINTS.PrismicWroom);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tsignature: args.signature,\n\t\t\tdocuments: JSON.stringify(args.documents),\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tlet reason: string | null = null;\n\t\t\ttry {\n\t\t\t\treason = await res.text();\n\t\t\t} catch {\n\t\t\t\t// Noop\n\t\t\t}\n\n\t\t\t// Ideally the API should throw a 409 or something like that...\n\t\t\tif (reason === \"Repository should not contain documents\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, repository is not empty`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, ${res.status} ${res.statusText}`,\n\t\t\t\t{\n\t\t\t\t\tcause: reason,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushChanges(\n\t\targs: TransactionalMergeArgs,\n\t): Promise<TransactionalMergeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\ttry {\n\t\t\t// Update the AWS ACL before uploading screenshots as it might have expired\n\t\t\tawait this.screenshots.initS3ACL();\n\n\t\t\tconst allChanges: AllChangeTypes[] = await Promise.all(\n\t\t\t\targs.changes.map(async (change) => {\n\t\t\t\t\tif (change.type === \"Slice\") {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\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\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_INSERT,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\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\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_UPDATE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\tawait this.screenshots.deleteScreenshotFolder({\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_INSERT,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_DELETE,\n\t\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\n\t\t\t// Compute the POST body\n\t\t\tconst requestBody: PushBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./push\", API_ENDPOINTS.SliceMachineV1),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: repositoryName,\n\t\t\t});\n\n\t\t\tswitch (response.status) {\n\t\t\t\tcase 202:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.SOFT,\n\t\t\t\t\t);\n\t\t\t\tcase 204:\n\t\t\t\t\treturn null;\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\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.HARD,\n\t\t\t\t\t);\n\t\t\t\tcase 400:\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tthrow new Error(text);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected status code ${response.status}`, {\n\t\t\t\t\t\tcause: await response.text(),\n\t\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\"An error happened while pushing your changes\");\n\t\t\tconsole.error(err);\n\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync fetchEnvironments(\n\t\targs?: PrismicRepositoryManagerFetchEnvironmentsArgs,\n\t): Promise<PrismicRepositoryManagerFetchEnvironmentsReturnType> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\n\t\t\tconst { value, error } = decode(\n\t\t\t\tt.union([\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tresults: t.array(Environment),\n\t\t\t\t\t}),\n\t\t\t\t\tt.type({\n\t\t\t\t\t\terror: t.literal(\"invalid_token\"),\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode environments: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\"results\" in value) {\n\t\t\t\tlet environments = value.results;\n\n\t\t\t\tif (!args?.includeAll) {\n\t\t\t\t\tconst profile = await this.user.getProfile();\n\n\t\t\t\t\tenvironments = environments.filter((environment) =>\n\t\t\t\t\t\tenvironment.users.some((user) => user.id === profile.shortId),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { environments: sortEnvironments(environments) };\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch environments.\");\n\t\t}\n\t}\n\n\tasync fetchOnboarding(): Promise<OnboardingState> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(OnboardingState, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch onboarding.\");\n\t\t}\n\t}\n\n\tasync toggleOnboardingStep(\n\t\tstepId: string,\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\n\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding step toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding step.\");\n\t\t}\n\t}\n\n\tasync completeOnboardingStep(\n\t\t...stepIds: string[]\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst currentState = await this.fetchOnboarding();\n\t\tconst incompleteSteps = stepIds.filter(\n\t\t\t(stepId) => !currentState.completedSteps.includes(stepId),\n\t\t);\n\n\t\tif (incompleteSteps.length > 0) {\n\t\t\t// TODO: Refactor when the API accepts multiple steps (DT-2389)\n\t\t\tfor await (const stepId of incompleteSteps) {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\t\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\t\t\tif (res.ok) {\n\t\t\t\t\tconst json = await res.json();\n\t\t\t\t\tconst { value, error } = decode(\n\t\t\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\t\t\tjson,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\t\t`Failed to decode onboarding step complete response: ${error.errors.join(\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\t\t\t\t\t}\n\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tcurrentState.completedSteps = value.completedSteps;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch (res.status) {\n\t\t\t\t\tcase 400:\n\t\t\t\t\tcase 401:\n\t\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\t\tcase 403:\n\t\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\"Failed to complete onboarding step.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { completedSteps: currentState.completedSteps };\n\t}\n\n\tasync toggleOnboarding(): Promise<{ isDismissed: boolean }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding/toggle\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ isDismissed: z.boolean() }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding guide.\");\n\t\t}\n\t}\n\n\tasync setDefaultMasterLocale(): Promise<void> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./repository/locales\", API_ENDPOINTS.LocaleService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tid: \"en-us\",\n\t\t\t\tisMaster: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 400:\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\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(\"Failed to set main content language.\", {\n\t\t\t\t\t\tcause: text,\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: PushChangesLimitType,\n\t): PushChangesLimit | null {\n\t\treturn fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(\n\t\t\t() => {\n\t\t\t\tconst error: ClientError = {\n\t\t\t\t\tstatus: statusCode,\n\t\t\t\t\tmessage: `Unable to parse raw limit from ${JSON.stringify(\n\t\t\t\t\t\tpotentialLimit,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(rawLimit: PushChangesRawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(PushChangesRawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\" | \"PATCH\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t\tskipAuthentication?: boolean;\n\t}): Promise<Response> {\n\t\tlet cookies;\n\t\ttry {\n\t\t\tcookies = await this.user.getAuthenticationCookies();\n\t\t} catch (e) {\n\t\t\tif (!args.skipAuthentication) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tconst extraHeaders: Record<string, string> = {};\n\n\t\tif (args.body) {\n\t\t\textraHeaders[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\textraHeaders.repository = args.repository;\n\t\t}\n\n\t\treturn await fetch(args.url.toString(), {\n\t\t\tmethod: args.method,\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\t// Some endpoints rely on the authorization header...\n\n\t\t\t\t...(cookies !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\t\t\t\tCookie: serializeCookies(cookies),\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...extraHeaders,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["BaseManager","API_ENDPOINTS","decode","t","PrismicRepository","PrismicRepositoryRole","PrismicRepositoryUserAgent","REPOSITORY_NAME_VALIDATION","assertPluginsInitialized","UnauthenticatedError","ChangeTypes","PushChangesLimitType","Environment","UnexpectedDataError","sortEnvironments","UnauthorizedError","OnboardingState","z","fold","PushChangesRawLimit","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AK;AAAA,MACb,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAGR,GAAI,YAAY,SACb;AAAA,UACA,eAAe,UAAU,QAAQ,cAAc;AAAA,UAC/C,QAAQC,kCAAiB,OAAO;AAAA,QAAA,IAEhC;QACH,cAAc,KAAK,aAAaC,yBAAA;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;;"}
|
1
|
+
{"version":3,"file":"PrismicRepositoryManager.cjs","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { z } from \"zod\";\nimport fetch, { Response } from \"../../lib/fetch\";\nimport { fold } from \"fp-ts/Either\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decode } from \"../../lib/decode\";\nimport { serializeCookies } from \"../../lib/serializeCookies\";\n\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { REPOSITORY_NAME_VALIDATION } from \"../../constants/REPOSITORY_NAME_VALIDATION\";\n\nimport {\n\tUnauthenticatedError,\n\tUnauthorizedError,\n\tUnexpectedDataError,\n} from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tPushBody,\n\tChangeTypes,\n\tClientError,\n\tPushChangesLimit,\n\tPushChangesLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tPushChangesRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n\tFrameworkWroomTelemetryID,\n\tStarterId,\n\tEnvironment,\n\tOnboardingState,\n} from \"./types\";\nimport { sortEnvironments } from \"./sortEnvironments\";\n\nconst DEFAULT_REPOSITORY_SETTINGS = {\n\tplan: \"personal\",\n\tisAnnual: \"false\",\n\trole: \"developer\",\n};\n\ntype PrismicRepositoryManagerCheckExistsArgs = {\n\tdomain: string;\n};\n\ntype PrismicRepositoryManagerCreateArgs = {\n\tdomain: string;\n\tframework: FrameworkWroomTelemetryID;\n\tstarterId?: StarterId;\n};\n\ntype PrismicRepositoryManagerDeleteArgs = {\n\tdomain: string;\n\tpassword: string;\n};\n\ntype PrismicRepositoryManagerPushDocumentsArgs = {\n\tdomain: string;\n\tsignature: string;\n\tdocuments: Record<string, unknown>; // TODO: Type unknown if possible(?)\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsArgs = {\n\t/**\n\t * If set to `true`, all environments are returned regardless of the user's\n\t * permission level.\n\t *\n\t * If set to `false`, only environments the user can access are returned.\n\t *\n\t * @defaultValue `false`\n\t */\n\tincludeAll?: boolean;\n};\n\ntype PrismicRepositoryManagerFetchEnvironmentsReturnType = {\n\tenvironments?: Environment[];\n};\n\nexport class PrismicRepositoryManager extends BaseManager {\n\t// TODO: Add methods for repository-specific actions. E.g. creating a\n\t// new repository.\n\n\tasync readAll(): Promise<PrismicRepository[]> {\n\t\tconst url = new URL(\"./repositories\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value: repositories, error } = decode(\n\t\t\t\tt.array(PrismicRepository),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to decode repositories: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn repositories;\n\t\t} else {\n\t\t\tconst text = await res.text();\n\t\t\tthrow new Error(`Failed to read repositories`, { cause: text });\n\t\t}\n\t}\n\n\t// Should this be in manager? It's one of the few sync method\n\t//\n\t// Reply from Angelo 2022-12-22: I think it should be in manager\n\t// because we shouldn't be exporting root-level utilities from this\n\t// package. If we want to make it more inline with the other methods,\n\t// we could simplify the API by changing its signature to the\n\t// following:\n\t//\n\t// ```ts\n\t// (repositoryName: string) => Promise<boolean>\n\t// ```\n\t//\n\t// This method would:\n\t//\n\t// 1. Fetch the list of repositories for the user using `readAll()`.\n\t// The list would be cached.\n\t// 2. Determine if the user has write access to the given repository.\n\t//\n\t// This version has the following benefits:\n\t//\n\t// - Does not expect the consumer to supply a repository object; it\n\t// only requires a repository name, which could be sourced from\n\t// anything (incl. the project's `slicemachine.config.json`).\n\t//\n\t// - Similarly, it does not expect the consumer to call `readAll()`\n\t// before calling this method.\n\t//\n\t// - Works for repositories that the user does not have access to. For\n\t// example, I could use it to check if I have access to \"qwerty\",\n\t// even if I am not added as a user. The purpose of the method is\n\t// still valid: do I have write access to a given repository?\n\thasWriteAccess(repository: PrismicRepository): boolean {\n\t\tswitch (repository.role) {\n\t\t\tcase PrismicRepositoryRole.SuperUser:\n\t\t\tcase PrismicRepositoryRole.Owner:\n\t\t\tcase PrismicRepositoryRole.Administrator:\n\t\t\t\treturn true;\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync checkExists(\n\t\targs: PrismicRepositoryManagerCheckExistsArgs,\n\t): Promise<boolean> {\n\t\tconst url = new URL(\n\t\t\t`./app/dashboard/repositories/${args.domain}/exists`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tskipAuthentication: true,\n\t\t});\n\n\t\tconst text = await res.text();\n\n\t\tif (res.ok) {\n\t\t\treturn text === \"false\"; // Endpoint returns `false` when repository exists\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to check repository existence for domain \\`${args.domain}\\``,\n\t\t\t\t{ cause: text },\n\t\t\t);\n\t\t}\n\t}\n\n\tasync create(args: PrismicRepositoryManagerCreateArgs): Promise<void> {\n\t\tconst url = new URL(\n\t\t\t\"./authentication/newrepository?app=slicemachine\",\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\n\t\tconst body = {\n\t\t\t...DEFAULT_REPOSITORY_SETTINGS,\n\t\t\tdomain: args.domain,\n\t\t\t// These properties are optional in the API but needed for tracking\n\t\t\tframework: args.framework,\n\t\t\tstarterId: args.starterId,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.SliceMachine, // Custom User Agent is required\n\t\t});\n\t\tconst text = await res.text();\n\n\t\t// Endpoint returns repository name on success, that should be within the validation range\n\t\t// Even when there is an error, we get a 200 success and so we have to check the name thanks to that\n\t\tif (\n\t\t\t!res.ok ||\n\t\t\ttext.length < REPOSITORY_NAME_VALIDATION.Min ||\n\t\t\ttext.length > REPOSITORY_NAME_VALIDATION.Max\n\t\t) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: text,\n\t\t\t});\n\t\t}\n\t}\n\n\t// TODO: Delete this endpoint? It doesn't seem to be used (I might be wrong). - Angelo\n\tasync delete(args: PrismicRepositoryManagerDeleteArgs): Promise<void> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\n\n\t\tconst url = new URL(\n\t\t\t`./app/settings/delete?_=${cookies[\"X_XSRF\"]}`, // TODO: Maybe we want to throw early if the token is no available, or get the token another way\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tconfirm: args.domain,\n\t\t\tpassword: args.password,\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(`Failed to delete repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync pushDocuments(\n\t\targs: PrismicRepositoryManagerPushDocumentsArgs,\n\t): Promise<void> {\n\t\tconst url = new URL(\"./starter/documents\", API_ENDPOINTS.PrismicWroom);\n\t\t// Update hostname to include repository domain\n\t\turl.hostname = `${args.domain}.${url.hostname}`;\n\n\t\tconst body = {\n\t\t\tsignature: args.signature,\n\t\t\tdocuments: JSON.stringify(args.documents),\n\t\t};\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\tuserAgent: PrismicRepositoryUserAgent.LegacyZero, // Custom User Agent is required\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tlet reason: string | null = null;\n\t\t\ttry {\n\t\t\t\treason = await res.text();\n\t\t\t} catch {\n\t\t\t\t// Noop\n\t\t\t}\n\n\t\t\t// Ideally the API should throw a 409 or something like that...\n\t\t\tif (reason === \"Repository should not contain documents\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, repository is not empty`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcause: reason,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to push documents to repository \\`${args.domain}\\`, ${res.status} ${res.statusText}`,\n\t\t\t\t{\n\t\t\t\t\tcause: reason,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushChanges(\n\t\targs: TransactionalMergeArgs,\n\t): Promise<TransactionalMergeReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tif (!(await this.user.checkIsLoggedIn())) {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\n\t\ttry {\n\t\t\t// Update the AWS ACL before uploading screenshots as it might have expired\n\t\t\tawait this.screenshots.initS3ACL();\n\n\t\t\tconst allChanges: AllChangeTypes[] = await Promise.all(\n\t\t\t\targs.changes.map(async (change) => {\n\t\t\t\t\tif (change.type === \"Slice\") {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\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\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_INSERT,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.slices.readSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\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\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst modelWithScreenshots =\n\t\t\t\t\t\t\t\t\tawait this.slices.updateSliceModelScreenshotsInPlace({\n\t\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: modelWithScreenshots,\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_UPDATE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\tawait this.screenshots.deleteScreenshotFolder({\n\t\t\t\t\t\t\t\t\tsliceID: change.id,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.SLICE_DELETE,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tswitch (change.status) {\n\t\t\t\t\t\t\tcase \"NEW\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_INSERT,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"MODIFIED\": {\n\t\t\t\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!model) {\n\t\t\t\t\t\t\t\t\tthrow Error(`Could not find model ${change.id}`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE,\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: model,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"DELETED\":\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: change.id,\n\t\t\t\t\t\t\t\t\tpayload: { id: change.id },\n\t\t\t\t\t\t\t\t\ttype: ChangeTypes.CUSTOM_TYPE_DELETE,\n\t\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\n\t\t\t// Compute the POST body\n\t\t\tconst requestBody: PushBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst repositoryName = await this.project.getResolvedRepositoryName();\n\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./push\", API_ENDPOINTS.SliceMachineV1),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: repositoryName,\n\t\t\t});\n\n\t\t\tswitch (response.status) {\n\t\t\t\tcase 202:\n\t\t\t\t\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.SOFT,\n\t\t\t\t\t);\n\t\t\t\tcase 204:\n\t\t\t\t\treturn null;\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\treturn this._decodeLimitOrThrow(\n\t\t\t\t\t\tawait response.json(),\n\t\t\t\t\t\tresponse.status,\n\t\t\t\t\t\tPushChangesLimitType.HARD,\n\t\t\t\t\t);\n\t\t\t\tcase 400:\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\tthrow new Error(text);\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`Unexpected status code ${response.status}`, {\n\t\t\t\t\t\tcause: await response.text(),\n\t\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\"An error happened while pushing your changes\");\n\t\t\tconsole.error(err);\n\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync fetchEnvironments(\n\t\targs?: PrismicRepositoryManagerFetchEnvironmentsArgs,\n\t): Promise<PrismicRepositoryManagerFetchEnvironmentsReturnType> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\n\t\t\tconst { value, error } = decode(\n\t\t\t\tt.union([\n\t\t\t\t\tt.type({\n\t\t\t\t\t\tresults: t.array(Environment),\n\t\t\t\t\t}),\n\t\t\t\t\tt.type({\n\t\t\t\t\t\terror: t.literal(\"invalid_token\"),\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode environments: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (\"results\" in value) {\n\t\t\t\tlet environments = value.results;\n\n\t\t\t\tif (!args?.includeAll) {\n\t\t\t\t\tconst profile = await this.user.getProfile();\n\n\t\t\t\t\tenvironments = environments.filter((environment) =>\n\t\t\t\t\t\tenvironment.users.some((user) => user.id === profile.shortId),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn { environments: sortEnvironments(environments) };\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch environments.\");\n\t\t}\n\t}\n\n\tasync fetchOnboarding(): Promise<OnboardingState> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(OnboardingState, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to fetch onboarding.\");\n\t\t}\n\t}\n\n\tasync toggleOnboardingStep(\n\t\tstepId: string,\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\n\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding step toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding step.\");\n\t\t}\n\t}\n\n\tasync completeOnboardingStep(\n\t\t...stepIds: string[]\n\t): Promise<{ completedSteps: string[] }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst currentState = await this.fetchOnboarding();\n\t\tconst incompleteSteps = stepIds.filter(\n\t\t\t(stepId) => !currentState.completedSteps.includes(stepId),\n\t\t);\n\n\t\tif (incompleteSteps.length > 0) {\n\t\t\t// TODO: Refactor when the API accepts multiple steps (DT-2389)\n\t\t\tfor await (const stepId of incompleteSteps) {\n\t\t\t\tconst url = new URL(\n\t\t\t\t\t`./onboarding/${stepId}/toggle`,\n\t\t\t\t\tAPI_ENDPOINTS.RepositoryService,\n\t\t\t\t);\n\t\t\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\t\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\t\t\tif (res.ok) {\n\t\t\t\t\tconst json = await res.json();\n\t\t\t\t\tconst { value, error } = decode(\n\t\t\t\t\t\tz.object({ completedSteps: z.array(z.string()) }),\n\t\t\t\t\t\tjson,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\t\t`Failed to decode onboarding step complete response: ${error.errors.join(\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\t\t\t\t\t}\n\n\t\t\t\t\tif (value) {\n\t\t\t\t\t\tcurrentState.completedSteps = value.completedSteps;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch (res.status) {\n\t\t\t\t\tcase 400:\n\t\t\t\t\tcase 401:\n\t\t\t\t\t\tthrow new UnauthenticatedError();\n\t\t\t\t\tcase 403:\n\t\t\t\t\t\tthrow new UnauthorizedError();\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(\"Failed to complete onboarding step.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { completedSteps: currentState.completedSteps };\n\t}\n\n\tasync toggleOnboarding(): Promise<{ isDismissed: boolean }> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./onboarding/toggle\", API_ENDPOINTS.RepositoryService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\t\tconst res = await this._fetch({ url, method: \"PATCH\" });\n\n\t\tif (res.ok) {\n\t\t\tconst json = await res.json();\n\t\t\tconst { value, error } = decode(\n\t\t\t\tz.object({ isDismissed: z.boolean() }),\n\t\t\t\tjson,\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t`Failed to decode onboarding toggle: ${error.errors.join(\", \")}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (value) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\n\t\tswitch (res.status) {\n\t\t\tcase 400:\n\t\t\tcase 401:\n\t\t\t\tthrow new UnauthenticatedError();\n\t\t\tcase 403:\n\t\t\t\tthrow new UnauthorizedError();\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Failed to toggle onboarding guide.\");\n\t\t}\n\t}\n\n\tasync setDefaultMasterLocale(): Promise<void> {\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\n\t\tconst url = new URL(\"./repository/locales\", API_ENDPOINTS.LocaleService);\n\t\turl.searchParams.set(\"repository\", repositoryName);\n\n\t\tconst res = await this._fetch({\n\t\t\turl,\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tid: \"en-us\",\n\t\t\t\tisMaster: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tswitch (res.status) {\n\t\t\t\tcase 400:\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\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(\"Failed to set main content language.\", {\n\t\t\t\t\t\tcause: text,\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: PushChangesLimitType,\n\t): PushChangesLimit | null {\n\t\treturn fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(\n\t\t\t() => {\n\t\t\t\tconst error: ClientError = {\n\t\t\t\t\tstatus: statusCode,\n\t\t\t\t\tmessage: `Unable to parse raw limit from ${JSON.stringify(\n\t\t\t\t\t\tpotentialLimit,\n\t\t\t\t\t)}`,\n\t\t\t\t};\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(rawLimit: PushChangesRawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(PushChangesRawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\" | \"PATCH\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t\tskipAuthentication?: boolean;\n\t}): Promise<Response> {\n\t\tlet cookies;\n\t\ttry {\n\t\t\tcookies = await this.user.getAuthenticationCookies();\n\t\t} catch (e) {\n\t\t\tif (!args.skipAuthentication) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tconst extraHeaders: Record<string, string> = {};\n\n\t\tif (args.body) {\n\t\t\textraHeaders[\"Content-Type\"] = \"application/json\";\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\textraHeaders.repository = args.repository;\n\t\t}\n\n\t\treturn await fetch(args.url.toString(), {\n\t\t\tmethod: args.method,\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\t// Some endpoints rely on the authorization header...\n\n\t\t\t\t...(cookies !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\t\t\t\tCookie: serializeCookies(cookies),\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\t\"User-Agent\": args.userAgent || SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...extraHeaders,\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["BaseManager","API_ENDPOINTS","decode","t","PrismicRepository","PrismicRepositoryRole","PrismicRepositoryUserAgent","REPOSITORY_NAME_VALIDATION","assertPluginsInitialized","UnauthenticatedError","ChangeTypes","PushChangesLimitType","Environment","UnexpectedDataError","sortEnvironments","UnauthorizedError","OnboardingState","z","fold","PushChangesRawLimit","fetch","serializeCookies","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,8BAA8B;AAAA,EACnC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;;AAwCD,MAAO,iCAAiCA,YAAAA,YAAW;AAAA;AAAA;AAAA,EAIxD,MAAM,UAAO;AACZ,UAAM,MAAM,IAAI,IAAI,kBAAkBC,4BAAc,WAAW;AAC/D,UAAM,MAAM,MAAM,KAAK,OAAO,EAAE,IAAK,CAAA;AAErC,QAAI,IAAI,IAAI;AACL,YAAA,OAAO,MAAM,IAAI;AACjB,YAAA,EAAE,OAAO,cAAc,UAAUC,OAAAA,OACtCC,aAAE,MAAMC,MAAAA,iBAAiB,GACzB,IAAI;AAGL,UAAI,OAAO;AACJ,cAAA,IAAI,MACT,kCAAkC,MAAM,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,MAE7D;AAEO,aAAA;AAAA,IAAA,OACD;AACA,YAAA,OAAO,M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