@slicemachine/manager 0.2.0 → 0.2.2-dev-page-types.0
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/common-tags/es/stripIndent/stripIndent.cjs +2 -1
- package/dist/_node_modules/common-tags/es/stripIndent/stripIndent.cjs.map +1 -1
- package/dist/_node_modules/common-tags/es/stripIndent/stripIndent.js +2 -1
- package/dist/_node_modules/common-tags/es/stripIndent/stripIndent.js.map +1 -1
- package/dist/auth/PrismicAuthManager.cjs +5 -4
- package/dist/auth/PrismicAuthManager.cjs.map +1 -1
- package/dist/auth/PrismicAuthManager.d.ts +58 -58
- package/dist/auth/PrismicAuthManager.js +5 -4
- package/dist/auth/PrismicAuthManager.js.map +1 -1
- package/dist/auth/createPrismicAuthManager.d.ts +4 -4
- package/dist/auth/createPrismicAuthManagerMiddleware.d.ts +14 -14
- package/dist/client/index.d.ts +6 -6
- package/dist/constants/API_ENDPOINTS.d.ts +8 -8
- package/dist/constants/API_TOKENS.d.ts +5 -5
- package/dist/constants/APPLICATION_MODE.d.ts +5 -5
- package/dist/constants/DEFAULT_SLICE_SCREENSHOT_URL.d.ts +5 -5
- package/dist/constants/SLICE_MACHINE_CONFIG_FILENAME.d.ts +1 -1
- package/dist/constants/SLICE_MACHINE_GITHUB_PACKAGE_NAME.d.ts +1 -1
- package/dist/constants/SLICE_MACHINE_GITHUB_REPOSITORY_NAME.d.ts +1 -1
- package/dist/constants/SLICE_MACHINE_GITHUB_REPOSITORY_ORGANIZATION.d.ts +1 -1
- package/dist/constants/SLICE_MACHINE_NPM_PACKAGE_NAME.d.ts +1 -1
- package/dist/constants/SLICE_MACHINE_USER_AGENT.d.ts +1 -1
- package/dist/constants/TS_CONFIG_FILENAME.d.ts +1 -1
- package/dist/constants/VERSION_KIND.d.ts +6 -6
- package/dist/errors.d.ts +34 -34
- package/dist/index.d.ts +11 -11
- package/dist/lib/DecodeError.d.ts +12 -12
- package/dist/lib/addTrailingSlash.d.ts +1 -1
- package/dist/lib/assertPluginsInitialized.d.ts +2 -2
- package/dist/lib/bufferCodec.d.ts +4 -4
- package/dist/lib/buildPrismicRepositoryAPIEndpoint.d.ts +4 -4
- package/dist/lib/castArray.d.ts +1 -1
- package/dist/lib/checkIsURLAccessible.d.ts +1 -1
- package/dist/lib/createContentDigest.d.ts +9 -9
- package/dist/lib/decode.d.ts +10 -10
- package/dist/lib/decodeHookResult.d.ts +10 -10
- package/dist/lib/decodePackageJSON.d.ts +12 -12
- package/dist/lib/decodeSliceMachineConfig.d.ts +3 -3
- package/dist/lib/fetchGitHubReleaseBodyForRelease.d.ts +21 -21
- package/dist/lib/fetchNPMPackageVersions.d.ts +5 -5
- package/dist/lib/format.d.ts +12 -12
- package/dist/lib/functionCodec.d.ts +2 -2
- package/dist/lib/installDependencies.d.ts +13 -13
- package/dist/lib/locateFileUpward.d.ts +10 -10
- package/dist/lib/markdownToHTML.d.ts +1 -1
- package/dist/lib/mockSlice.d.ts +9 -9
- package/dist/lib/prismicrc.d.ts +10 -10
- package/dist/lib/serializeCookies.d.ts +6 -6
- package/dist/managers/BaseManager.d.ts +33 -33
- package/dist/managers/SliceMachineManager.d.ts +95 -95
- package/dist/managers/createSliceMachineManager.d.ts +5 -5
- package/dist/managers/createSliceMachineManagerClient.d.ts +8 -8
- package/dist/managers/createSliceMachineManagerMiddleware.d.ts +15 -15
- package/dist/managers/customTypes/CustomTypesManager.d.ts +56 -56
- package/dist/managers/plugins/PluginsManager.d.ts +13 -13
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +5 -12
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.d.ts +30 -30
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js +5 -12
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/prismicRepository/types.d.ts +123 -123
- package/dist/managers/project/ProjectManager.d.ts +49 -49
- package/dist/managers/screenshots/ScreenshotsManager.cjs +6 -5
- package/dist/managers/screenshots/ScreenshotsManager.cjs.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.d.ts +34 -34
- package/dist/managers/screenshots/ScreenshotsManager.js +6 -5
- package/dist/managers/screenshots/ScreenshotsManager.js.map +1 -1
- package/dist/managers/simulator/SimulatorManager.d.ts +38 -38
- package/dist/managers/slices/SlicesManager.cjs +1 -5
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.d.ts +128 -128
- package/dist/managers/slices/SlicesManager.js +1 -5
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/dist/managers/snippets/SnippetsManager.d.ts +11 -11
- package/dist/managers/telemetry/TelemetryManager.d.ts +30 -30
- package/dist/managers/telemetry/types.d.ts +143 -143
- package/dist/managers/user/UserManager.d.ts +40 -40
- package/dist/managers/versions/VersionsManager.d.ts +19 -19
- package/dist/managers/versions/types.d.ts +5 -5
- package/dist/test/createSliceMachineManagerMSWHandler.d.ts +7 -7
- package/dist/test/index.d.ts +2 -2
- package/dist/types.d.ts +45 -45
- package/package.json +3 -3
- package/src/auth/PrismicAuthManager.ts +5 -9
- package/src/managers/prismicRepository/PrismicRepositoryManager.ts +5 -12
- package/src/managers/screenshots/ScreenshotsManager.ts +12 -5
- package/src/managers/slices/SlicesManager.ts +1 -6
|
@@ -166,6 +166,7 @@ class PrismicRepositoryManager extends BaseManager {
|
|
|
166
166
|
throw new UnauthenticatedError();
|
|
167
167
|
}
|
|
168
168
|
try {
|
|
169
|
+
await this.screenshots.initS3ACL();
|
|
169
170
|
const allChanges = await Promise.all(args.changes.map(async (change) => {
|
|
170
171
|
if (change.type === "Slice") {
|
|
171
172
|
switch (change.status) {
|
|
@@ -181,14 +182,10 @@ class PrismicRepositoryManager extends BaseManager {
|
|
|
181
182
|
libraryID: change.libraryID,
|
|
182
183
|
model
|
|
183
184
|
});
|
|
184
|
-
await this.slices.updateSlice({
|
|
185
|
-
libraryID: change.libraryID,
|
|
186
|
-
model: modelWithScreenshots
|
|
187
|
-
});
|
|
188
185
|
return {
|
|
189
|
-
type: ChangeTypes.SLICE_INSERT,
|
|
190
186
|
id: change.id,
|
|
191
|
-
payload: modelWithScreenshots
|
|
187
|
+
payload: modelWithScreenshots,
|
|
188
|
+
type: ChangeTypes.SLICE_INSERT
|
|
192
189
|
};
|
|
193
190
|
}
|
|
194
191
|
case "MODIFIED": {
|
|
@@ -203,14 +200,10 @@ class PrismicRepositoryManager extends BaseManager {
|
|
|
203
200
|
libraryID: change.libraryID,
|
|
204
201
|
model
|
|
205
202
|
});
|
|
206
|
-
await this.slices.updateSlice({
|
|
207
|
-
libraryID: change.libraryID,
|
|
208
|
-
model: modelWithScreenshots
|
|
209
|
-
});
|
|
210
203
|
return {
|
|
211
|
-
type: ChangeTypes.SLICE_UPDATE,
|
|
212
204
|
id: change.id,
|
|
213
|
-
payload: modelWithScreenshots
|
|
205
|
+
payload: modelWithScreenshots,
|
|
206
|
+
type: ChangeTypes.SLICE_UPDATE
|
|
214
207
|
};
|
|
215
208
|
}
|
|
216
209
|
case "DELETED":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRepositoryManager.js","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport fetch, { Response } from \"node-fetch\";\nimport { fold } from \"fp-ts/Either\";\n\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\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tBulkBody,\n\tChangeTypes,\n\tClientError,\n\tLimit,\n\tLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n} from \"./types\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { UnauthenticatedError } from \"../../errors\";\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: string; // TODO: Type(?)\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\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\t\tconst json = await res.json();\n\n\t\tif (res.ok) {\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\tthrow new Error(`Failed to read repositories`, { cause: json });\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 `sm.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({ url });\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\tframework: args.framework, // This property appears to be optional for the API\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, which must be more than 4 characters and less than 30\n\t\t// if (!res.ok) {\n\t\tif (!res.ok || text.length < 4 || text.length > 30) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\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: res,\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: res,\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\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\tawait this.slices.updateSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tmodel: modelWithScreenshots,\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.SLICE_INSERT,\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};\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\tawait this.slices.updateSlice({\n\t\t\t\t\t\t\t\t\tlibraryID: change.libraryID,\n\t\t\t\t\t\t\t\t\tmodel: modelWithScreenshots,\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.SLICE_UPDATE,\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};\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: BulkBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\n\t\t\t// TODO: move to customtypes client\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./bulk\", API_ENDPOINTS.PrismicModels),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: sliceMachineConfig.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\tLimitType.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\tLimitType.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}\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\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: LimitType,\n\t): Limit | null {\n\t\treturn fold<t.Errors, RawLimit, Limit | 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: RawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(RawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t}): Promise<Response> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\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\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\tCookie: serializeCookies(cookies),\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":[],"mappings":";;;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AAC5D,cAAQ,MAAM,GAAG;AAEX,YAAA;AAAA,IACN;AAAA,EACF;AAAA,EAEQ,oBACP,gBACA,YACA,WAAoB;AAEpB,WAAO,KACN,MAAK;AACJ,YAAM,QAAqB;AAAA,QAC1B,QAAQ;AAAA,QACR,SAAS,kCAAkC,KAAK,UAC/C,cAAc;AAAA,MAAA;AAGV,YAAA;AAAA,IACP,GACA,CAAC,aAAsB;AACtB,YAAM,QAAQ,EAAE,GAAG,UAAU,MAAM,UAAS;AAErC,aAAA;AAAA,IACP,CAAA,EACA,SAAS,OAAO,cAAc,CAAC;AAAA,EAClC;AAAA,EAEQ,MAAM,OAAO,MAMpB;AACA,UAAM,UAAU,MAAM,KAAK,KAAK,yBAAwB;AAExD,UAAM,eAAuC,CAAA;AAE7C,QAAI,KAAK,MAAM;AACd,mBAAa,cAAc,IAAI;AAAA,IAC/B;AAED,QAAI,KAAK,YAAY;AACpB,mBAAa,aAAa,KAAK;AAAA,IAC/B;AAED,WAAO,MAAM,MAAM,KAAK,IAAI,YAAY;AAAA,MACvC,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAER,eAAe,UAAU,QAAQ,cAAc;AAAA,QAC/C,QAAQ,iBAAiB,OAAO;AAAA,QAChC,cAAc,KAAK,aAAa;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;"}
|
|
1
|
+
{"version":3,"file":"PrismicRepositoryManager.js","sources":["../../../../src/managers/prismicRepository/PrismicRepositoryManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport fetch, { Response } from \"node-fetch\";\nimport { fold } from \"fp-ts/Either\";\n\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\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tAllChangeTypes,\n\tBulkBody,\n\tChangeTypes,\n\tClientError,\n\tLimit,\n\tLimitType,\n\tPrismicRepository,\n\tPrismicRepositoryRole,\n\tPrismicRepositoryUserAgent,\n\tPrismicRepositoryUserAgents,\n\tRawLimit,\n\tTransactionalMergeArgs,\n\tTransactionalMergeReturnType,\n} from \"./types\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { UnauthenticatedError } from \"../../errors\";\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: string; // TODO: Type(?)\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\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\t\tconst json = await res.json();\n\n\t\tif (res.ok) {\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\tthrow new Error(`Failed to read repositories`, { cause: json });\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 `sm.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({ url });\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\tframework: args.framework, // This property appears to be optional for the API\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, which must be more than 4 characters and less than 30\n\t\t// if (!res.ok) {\n\t\tif (!res.ok || text.length < 4 || text.length > 30) {\n\t\t\tthrow new Error(`Failed to create repository \\`${args.domain}\\``, {\n\t\t\t\tcause: res,\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: res,\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: res,\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: BulkBody = {\n\t\t\t\tconfirmDeleteDocuments: args.confirmDeleteDocuments,\n\t\t\t\tchanges: allChanges,\n\t\t\t};\n\n\t\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\n\t\t\t// TODO: move to customtypes client\n\t\t\tconst response = await this._fetch({\n\t\t\t\turl: new URL(\"./bulk\", API_ENDPOINTS.PrismicModels),\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: requestBody,\n\t\t\t\trepository: sliceMachineConfig.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\tLimitType.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\tLimitType.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}\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\tprivate _decodeLimitOrThrow(\n\t\tpotentialLimit: unknown,\n\t\tstatusCode: number,\n\t\tlimitType: LimitType,\n\t): Limit | null {\n\t\treturn fold<t.Errors, RawLimit, Limit | 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: RawLimit) => {\n\t\t\t\tconst limit = { ...rawLimit, type: limitType };\n\n\t\t\t\treturn limit;\n\t\t\t},\n\t\t)(RawLimit.decode(potentialLimit));\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\";\n\t\tbody?: unknown;\n\t\tuserAgent?: PrismicRepositoryUserAgents;\n\t\trepository?: string;\n\t}): Promise<Response> {\n\t\tconst cookies = await this.user.getAuthenticationCookies();\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\t\t\t\tAuthorization: `Bearer ${cookies[\"prismic-auth\"]}`,\n\t\t\t\tCookie: serializeCookies(cookies),\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":[],"mappings":";;;;;;;;;;;AA8BA,MAAM,8BAA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AK,UAC/C,cAAc;AAAA,MAAA;AAGV,YAAA;AAAA,IACP,GACA,CAAC,aAAsB;AACtB,YAAM,QAAQ,EAAE,GAAG,UAAU,MAAM,UAAS;AAErC,aAAA;AAAA,IACP,CAAA,EACA,SAAS,OAAO,cAAc,CAAC;AAAA,EAClC;AAAA,EAEQ,MAAM,OAAO,MAMpB;AACA,UAAM,UAAU,MAAM,KAAK,KAAK,yBAAwB;AAExD,UAAM,eAAuC,CAAA;AAE7C,QAAI,KAAK,MAAM;AACd,mBAAa,cAAc,IAAI;AAAA,IAC/B;AAED,QAAI,KAAK,YAAY;AACpB,mBAAa,aAAa,KAAK;AAAA,IAC/B;AAED,WAAO,MAAM,MAAM,KAAK,IAAI,YAAY;AAAA,MACvC,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA;AAAA,QAER,eAAe,UAAU,QAAQ,cAAc;AAAA,QAC/C,QAAQ,iBAAiB,OAAO;AAAA,QAChC,cAAc,KAAK,aAAa;AAAA,QAChC,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EACF;AACA;"}
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
import * as t from "io-ts";
|
|
3
|
-
export declare const PrismicRepositoryUserAgent: {
|
|
4
|
-
readonly SliceMachine: "prismic-cli/sm";
|
|
5
|
-
readonly LegacyZero: "prismic-cli/0";
|
|
6
|
-
};
|
|
7
|
-
export type PrismicRepositoryUserAgents = (typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];
|
|
8
|
-
export declare const PrismicRepositoryRole: {
|
|
9
|
-
readonly SuperUser: "SuperUser";
|
|
10
|
-
readonly Administrator: "Administrator";
|
|
11
|
-
readonly Owner: "Owner";
|
|
12
|
-
readonly Manager: "Manager";
|
|
13
|
-
readonly Publisher: "Publisher";
|
|
14
|
-
readonly Writer: "Writer";
|
|
15
|
-
readonly Readonly: "Readonly";
|
|
16
|
-
};
|
|
17
|
-
export type PrismicRepositoryRoles = (typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];
|
|
18
|
-
export declare const PrismicRepository: t.TypeC<{
|
|
19
|
-
domain: t.StringC;
|
|
20
|
-
name: t.StringC;
|
|
21
|
-
role: t.UnionC<[t.KeyofC<{
|
|
22
|
-
readonly SuperUser: "SuperUser";
|
|
23
|
-
readonly Administrator: "Administrator";
|
|
24
|
-
readonly Owner: "Owner";
|
|
25
|
-
readonly Manager: "Manager";
|
|
26
|
-
readonly Publisher: "Publisher";
|
|
27
|
-
readonly Writer: "Writer";
|
|
28
|
-
readonly Readonly: "Readonly";
|
|
29
|
-
}>, t.RecordC<t.StringC, t.KeyofC<{
|
|
30
|
-
readonly SuperUser: "SuperUser";
|
|
31
|
-
readonly Administrator: "Administrator";
|
|
32
|
-
readonly Owner: "Owner";
|
|
33
|
-
readonly Manager: "Manager";
|
|
34
|
-
readonly Publisher: "Publisher";
|
|
35
|
-
readonly Writer: "Writer";
|
|
36
|
-
readonly Readonly: "Readonly";
|
|
37
|
-
}>>]>;
|
|
38
|
-
}>;
|
|
39
|
-
export type PrismicRepository = t.TypeOf<typeof PrismicRepository>;
|
|
40
|
-
export declare enum ChangeTypes {
|
|
41
|
-
SLICE_INSERT = "SLICE_INSERT",
|
|
42
|
-
SLICE_UPDATE = "SLICE_UPDATE",
|
|
43
|
-
SLICE_DELETE = "SLICE_DELETE",
|
|
44
|
-
CUSTOM_TYPE_INSERT = "CUSTOM_TYPE_INSERT",
|
|
45
|
-
CUSTOM_TYPE_UPDATE = "CUSTOM_TYPE_UPDATE",
|
|
46
|
-
CUSTOM_TYPE_DELETE = "CUSTOM_TYPE_DELETE"
|
|
47
|
-
}
|
|
48
|
-
interface Change {
|
|
49
|
-
type: ChangeTypes;
|
|
50
|
-
id: string;
|
|
51
|
-
payload: Record<string, unknown>;
|
|
52
|
-
}
|
|
53
|
-
interface DeleteChange extends Change {
|
|
54
|
-
payload: {
|
|
55
|
-
id: Change["id"];
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
export interface SliceInsertChange extends Change {
|
|
59
|
-
type: ChangeTypes.SLICE_INSERT;
|
|
60
|
-
payload: SharedSlice;
|
|
61
|
-
}
|
|
62
|
-
export interface SliceUpdateChange extends Change {
|
|
63
|
-
type: ChangeTypes.SLICE_UPDATE;
|
|
64
|
-
payload: SharedSlice;
|
|
65
|
-
}
|
|
66
|
-
export interface SliceDeleteChange extends DeleteChange {
|
|
67
|
-
type: ChangeTypes.SLICE_DELETE;
|
|
68
|
-
}
|
|
69
|
-
export interface CustomTypeInsertChange extends Change {
|
|
70
|
-
type: ChangeTypes.CUSTOM_TYPE_INSERT;
|
|
71
|
-
payload: CustomType;
|
|
72
|
-
}
|
|
73
|
-
export interface CustomTypeUpdateChange extends Change {
|
|
74
|
-
type: ChangeTypes.CUSTOM_TYPE_UPDATE;
|
|
75
|
-
payload: CustomType;
|
|
76
|
-
}
|
|
77
|
-
export interface CustomTypeDeleteChange extends DeleteChange {
|
|
78
|
-
type: ChangeTypes.CUSTOM_TYPE_DELETE;
|
|
79
|
-
}
|
|
80
|
-
export type AllChangeTypes = SliceInsertChange | SliceUpdateChange | SliceDeleteChange | CustomTypeInsertChange | CustomTypeUpdateChange | CustomTypeDeleteChange;
|
|
81
|
-
export interface BulkBody extends Record<string, unknown> {
|
|
82
|
-
confirmDeleteDocuments: boolean;
|
|
83
|
-
changes: AllChangeTypes[];
|
|
84
|
-
}
|
|
85
|
-
export declare const RawLimit: t.TypeC<{
|
|
86
|
-
details: t.TypeC<{
|
|
87
|
-
customTypes: t.ArrayC<t.TypeC<{
|
|
88
|
-
id: t.StringC;
|
|
89
|
-
numberOfDocuments: t.NumberC;
|
|
90
|
-
url: t.StringC;
|
|
91
|
-
}>>;
|
|
92
|
-
}>;
|
|
93
|
-
}>;
|
|
94
|
-
export type RawLimit = t.TypeOf<typeof RawLimit>;
|
|
95
|
-
export declare enum LimitType {
|
|
96
|
-
SOFT = "SOFT",
|
|
97
|
-
HARD = "HARD"
|
|
98
|
-
}
|
|
99
|
-
export type Limit = RawLimit & {
|
|
100
|
-
type: LimitType;
|
|
101
|
-
};
|
|
102
|
-
export interface ClientError {
|
|
103
|
-
status: number;
|
|
104
|
-
message: string;
|
|
105
|
-
}
|
|
106
|
-
type ChangeStatus = "NEW" | "MODIFIED" | "DELETED";
|
|
107
|
-
type CustomTypeChange = {
|
|
108
|
-
id: string;
|
|
109
|
-
type: "CustomType";
|
|
110
|
-
status: ChangeStatus;
|
|
111
|
-
};
|
|
112
|
-
type SliceChange = {
|
|
113
|
-
id: string;
|
|
114
|
-
type: "Slice";
|
|
115
|
-
status: ChangeStatus;
|
|
116
|
-
libraryID: string;
|
|
117
|
-
};
|
|
118
|
-
export type TransactionalMergeArgs = {
|
|
119
|
-
confirmDeleteDocuments: boolean;
|
|
120
|
-
changes: (CustomTypeChange | SliceChange)[];
|
|
121
|
-
};
|
|
122
|
-
export type TransactionalMergeReturnType = Limit | null;
|
|
123
|
-
export {};
|
|
1
|
+
import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
import * as t from "io-ts";
|
|
3
|
+
export declare const PrismicRepositoryUserAgent: {
|
|
4
|
+
readonly SliceMachine: "prismic-cli/sm";
|
|
5
|
+
readonly LegacyZero: "prismic-cli/0";
|
|
6
|
+
};
|
|
7
|
+
export type PrismicRepositoryUserAgents = (typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];
|
|
8
|
+
export declare const PrismicRepositoryRole: {
|
|
9
|
+
readonly SuperUser: "SuperUser";
|
|
10
|
+
readonly Administrator: "Administrator";
|
|
11
|
+
readonly Owner: "Owner";
|
|
12
|
+
readonly Manager: "Manager";
|
|
13
|
+
readonly Publisher: "Publisher";
|
|
14
|
+
readonly Writer: "Writer";
|
|
15
|
+
readonly Readonly: "Readonly";
|
|
16
|
+
};
|
|
17
|
+
export type PrismicRepositoryRoles = (typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];
|
|
18
|
+
export declare const PrismicRepository: t.TypeC<{
|
|
19
|
+
domain: t.StringC;
|
|
20
|
+
name: t.StringC;
|
|
21
|
+
role: t.UnionC<[t.KeyofC<{
|
|
22
|
+
readonly SuperUser: "SuperUser";
|
|
23
|
+
readonly Administrator: "Administrator";
|
|
24
|
+
readonly Owner: "Owner";
|
|
25
|
+
readonly Manager: "Manager";
|
|
26
|
+
readonly Publisher: "Publisher";
|
|
27
|
+
readonly Writer: "Writer";
|
|
28
|
+
readonly Readonly: "Readonly";
|
|
29
|
+
}>, t.RecordC<t.StringC, t.KeyofC<{
|
|
30
|
+
readonly SuperUser: "SuperUser";
|
|
31
|
+
readonly Administrator: "Administrator";
|
|
32
|
+
readonly Owner: "Owner";
|
|
33
|
+
readonly Manager: "Manager";
|
|
34
|
+
readonly Publisher: "Publisher";
|
|
35
|
+
readonly Writer: "Writer";
|
|
36
|
+
readonly Readonly: "Readonly";
|
|
37
|
+
}>>]>;
|
|
38
|
+
}>;
|
|
39
|
+
export type PrismicRepository = t.TypeOf<typeof PrismicRepository>;
|
|
40
|
+
export declare enum ChangeTypes {
|
|
41
|
+
SLICE_INSERT = "SLICE_INSERT",
|
|
42
|
+
SLICE_UPDATE = "SLICE_UPDATE",
|
|
43
|
+
SLICE_DELETE = "SLICE_DELETE",
|
|
44
|
+
CUSTOM_TYPE_INSERT = "CUSTOM_TYPE_INSERT",
|
|
45
|
+
CUSTOM_TYPE_UPDATE = "CUSTOM_TYPE_UPDATE",
|
|
46
|
+
CUSTOM_TYPE_DELETE = "CUSTOM_TYPE_DELETE"
|
|
47
|
+
}
|
|
48
|
+
interface Change {
|
|
49
|
+
type: ChangeTypes;
|
|
50
|
+
id: string;
|
|
51
|
+
payload: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
interface DeleteChange extends Change {
|
|
54
|
+
payload: {
|
|
55
|
+
id: Change["id"];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface SliceInsertChange extends Change {
|
|
59
|
+
type: ChangeTypes.SLICE_INSERT;
|
|
60
|
+
payload: SharedSlice;
|
|
61
|
+
}
|
|
62
|
+
export interface SliceUpdateChange extends Change {
|
|
63
|
+
type: ChangeTypes.SLICE_UPDATE;
|
|
64
|
+
payload: SharedSlice;
|
|
65
|
+
}
|
|
66
|
+
export interface SliceDeleteChange extends DeleteChange {
|
|
67
|
+
type: ChangeTypes.SLICE_DELETE;
|
|
68
|
+
}
|
|
69
|
+
export interface CustomTypeInsertChange extends Change {
|
|
70
|
+
type: ChangeTypes.CUSTOM_TYPE_INSERT;
|
|
71
|
+
payload: CustomType;
|
|
72
|
+
}
|
|
73
|
+
export interface CustomTypeUpdateChange extends Change {
|
|
74
|
+
type: ChangeTypes.CUSTOM_TYPE_UPDATE;
|
|
75
|
+
payload: CustomType;
|
|
76
|
+
}
|
|
77
|
+
export interface CustomTypeDeleteChange extends DeleteChange {
|
|
78
|
+
type: ChangeTypes.CUSTOM_TYPE_DELETE;
|
|
79
|
+
}
|
|
80
|
+
export type AllChangeTypes = SliceInsertChange | SliceUpdateChange | SliceDeleteChange | CustomTypeInsertChange | CustomTypeUpdateChange | CustomTypeDeleteChange;
|
|
81
|
+
export interface BulkBody extends Record<string, unknown> {
|
|
82
|
+
confirmDeleteDocuments: boolean;
|
|
83
|
+
changes: AllChangeTypes[];
|
|
84
|
+
}
|
|
85
|
+
export declare const RawLimit: t.TypeC<{
|
|
86
|
+
details: t.TypeC<{
|
|
87
|
+
customTypes: t.ArrayC<t.TypeC<{
|
|
88
|
+
id: t.StringC;
|
|
89
|
+
numberOfDocuments: t.NumberC;
|
|
90
|
+
url: t.StringC;
|
|
91
|
+
}>>;
|
|
92
|
+
}>;
|
|
93
|
+
}>;
|
|
94
|
+
export type RawLimit = t.TypeOf<typeof RawLimit>;
|
|
95
|
+
export declare enum LimitType {
|
|
96
|
+
SOFT = "SOFT",
|
|
97
|
+
HARD = "HARD"
|
|
98
|
+
}
|
|
99
|
+
export type Limit = RawLimit & {
|
|
100
|
+
type: LimitType;
|
|
101
|
+
};
|
|
102
|
+
export interface ClientError {
|
|
103
|
+
status: number;
|
|
104
|
+
message: string;
|
|
105
|
+
}
|
|
106
|
+
type ChangeStatus = "NEW" | "MODIFIED" | "DELETED";
|
|
107
|
+
type CustomTypeChange = {
|
|
108
|
+
id: string;
|
|
109
|
+
type: "CustomType";
|
|
110
|
+
status: ChangeStatus;
|
|
111
|
+
};
|
|
112
|
+
type SliceChange = {
|
|
113
|
+
id: string;
|
|
114
|
+
type: "Slice";
|
|
115
|
+
status: ChangeStatus;
|
|
116
|
+
libraryID: string;
|
|
117
|
+
};
|
|
118
|
+
export type TransactionalMergeArgs = {
|
|
119
|
+
confirmDeleteDocuments: boolean;
|
|
120
|
+
changes: (CustomTypeChange | SliceChange)[];
|
|
121
|
+
};
|
|
122
|
+
export type TransactionalMergeReturnType = Limit | null;
|
|
123
|
+
export {};
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { ExecaChildProcess } from "execa";
|
|
2
|
-
import { PackageManager, SliceMachineConfig } from "../../types";
|
|
3
|
-
import { BaseManager } from "../BaseManager";
|
|
4
|
-
type ProjectManagerGetSliceMachineConfigPathArgs = {
|
|
5
|
-
ignoreCache?: boolean;
|
|
6
|
-
};
|
|
7
|
-
type ProjectManagerGetRootArgs = {
|
|
8
|
-
ignoreCache?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type ProjectManagerCheckIsTypeScriptArgs = {
|
|
11
|
-
rootOverride?: string;
|
|
12
|
-
};
|
|
13
|
-
type ProjectManagerWriteSliceMachineConfigArgs = {
|
|
14
|
-
config: SliceMachineConfig;
|
|
15
|
-
path?: string;
|
|
16
|
-
};
|
|
17
|
-
type ProjectManagerInitProjectArgs = {
|
|
18
|
-
log?: (message: string) => void;
|
|
19
|
-
};
|
|
20
|
-
type ProjectManagerDetectPackageManager = {
|
|
21
|
-
root?: string;
|
|
22
|
-
};
|
|
23
|
-
type ProjectManagerInstallDependenciesArgs = {
|
|
24
|
-
dependencies: Record<string, string>;
|
|
25
|
-
dev?: boolean;
|
|
26
|
-
packageManager?: PackageManager;
|
|
27
|
-
log?: (message: string) => void;
|
|
28
|
-
};
|
|
29
|
-
type ProjectManagerInstallDependenciesReturnType = {
|
|
30
|
-
execaProcess: ExecaChildProcess;
|
|
31
|
-
};
|
|
32
|
-
export declare class ProjectManager extends BaseManager {
|
|
33
|
-
private _cachedRoot;
|
|
34
|
-
private _cachedSliceMachineConfigPath;
|
|
35
|
-
private _cachedSliceMachineConfig;
|
|
36
|
-
getSliceMachineConfigPath(args?: ProjectManagerGetSliceMachineConfigPathArgs): Promise<string>;
|
|
37
|
-
getRoot(args?: ProjectManagerGetRootArgs): Promise<string>;
|
|
38
|
-
suggestRoot(): Promise<string>;
|
|
39
|
-
suggestSliceMachineConfigPath(): Promise<string>;
|
|
40
|
-
checkIsTypeScript(args?: ProjectManagerCheckIsTypeScriptArgs): Promise<boolean>;
|
|
41
|
-
getSliceMachineConfig(): Promise<SliceMachineConfig>;
|
|
42
|
-
writeSliceMachineConfig(args: ProjectManagerWriteSliceMachineConfigArgs): Promise<void>;
|
|
43
|
-
loadSliceMachineConfig(): Promise<SliceMachineConfig>;
|
|
44
|
-
locateSliceMachineUIDir(): Promise<string>;
|
|
45
|
-
initProject(args?: ProjectManagerInitProjectArgs): Promise<void>;
|
|
46
|
-
detectPackageManager(args?: ProjectManagerDetectPackageManager): Promise<PackageManager>;
|
|
47
|
-
installDependencies(args: ProjectManagerInstallDependenciesArgs): Promise<ProjectManagerInstallDependenciesReturnType>;
|
|
48
|
-
}
|
|
49
|
-
export {};
|
|
1
|
+
import { ExecaChildProcess } from "execa";
|
|
2
|
+
import { PackageManager, SliceMachineConfig } from "../../types";
|
|
3
|
+
import { BaseManager } from "../BaseManager";
|
|
4
|
+
type ProjectManagerGetSliceMachineConfigPathArgs = {
|
|
5
|
+
ignoreCache?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type ProjectManagerGetRootArgs = {
|
|
8
|
+
ignoreCache?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type ProjectManagerCheckIsTypeScriptArgs = {
|
|
11
|
+
rootOverride?: string;
|
|
12
|
+
};
|
|
13
|
+
type ProjectManagerWriteSliceMachineConfigArgs = {
|
|
14
|
+
config: SliceMachineConfig;
|
|
15
|
+
path?: string;
|
|
16
|
+
};
|
|
17
|
+
type ProjectManagerInitProjectArgs = {
|
|
18
|
+
log?: (message: string) => void;
|
|
19
|
+
};
|
|
20
|
+
type ProjectManagerDetectPackageManager = {
|
|
21
|
+
root?: string;
|
|
22
|
+
};
|
|
23
|
+
type ProjectManagerInstallDependenciesArgs = {
|
|
24
|
+
dependencies: Record<string, string>;
|
|
25
|
+
dev?: boolean;
|
|
26
|
+
packageManager?: PackageManager;
|
|
27
|
+
log?: (message: string) => void;
|
|
28
|
+
};
|
|
29
|
+
type ProjectManagerInstallDependenciesReturnType = {
|
|
30
|
+
execaProcess: ExecaChildProcess;
|
|
31
|
+
};
|
|
32
|
+
export declare class ProjectManager extends BaseManager {
|
|
33
|
+
private _cachedRoot;
|
|
34
|
+
private _cachedSliceMachineConfigPath;
|
|
35
|
+
private _cachedSliceMachineConfig;
|
|
36
|
+
getSliceMachineConfigPath(args?: ProjectManagerGetSliceMachineConfigPathArgs): Promise<string>;
|
|
37
|
+
getRoot(args?: ProjectManagerGetRootArgs): Promise<string>;
|
|
38
|
+
suggestRoot(): Promise<string>;
|
|
39
|
+
suggestSliceMachineConfigPath(): Promise<string>;
|
|
40
|
+
checkIsTypeScript(args?: ProjectManagerCheckIsTypeScriptArgs): Promise<boolean>;
|
|
41
|
+
getSliceMachineConfig(): Promise<SliceMachineConfig>;
|
|
42
|
+
writeSliceMachineConfig(args: ProjectManagerWriteSliceMachineConfigArgs): Promise<void>;
|
|
43
|
+
loadSliceMachineConfig(): Promise<SliceMachineConfig>;
|
|
44
|
+
locateSliceMachineUIDir(): Promise<string>;
|
|
45
|
+
initProject(args?: ProjectManagerInitProjectArgs): Promise<void>;
|
|
46
|
+
detectPackageManager(args?: ProjectManagerDetectPackageManager): Promise<PackageManager>;
|
|
47
|
+
installDependencies(args: ProjectManagerInstallDependenciesArgs): Promise<ProjectManagerInstallDependenciesReturnType>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -97,13 +97,14 @@ class ScreenshotsManager extends BaseManager.BaseManager {
|
|
|
97
97
|
} catch {
|
|
98
98
|
throw new errors.InternalError("Screenshots require Puppeteer but Puppeteer was not found. Check that the `puppeteer` package is installed before trying again.");
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
try {
|
|
101
|
+
const browser = await puppeteer.launch({ headless: "new" });
|
|
102
|
+
this._browserContext = await browser.createIncognitoBrowserContext();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new errors.InternalError("Error launching browser. If you're using an Apple Silicon Mac, check if Rosetta is installed.");
|
|
105
|
+
}
|
|
102
106
|
}
|
|
103
107
|
async initS3ACL() {
|
|
104
|
-
if (this._s3ACL) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
108
|
const awsACLURL = new URL("create", API_ENDPOINTS.API_ENDPOINTS.AwsAclProvider);
|
|
108
109
|
const awsACLRes = await this._fetch({ url: awsACLURL });
|
|
109
110
|
const awsACLText = await awsACLRes.text();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScreenshotsManager.cjs","sources":["../../../../src/managers/screenshots/ScreenshotsManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport fetch, { FormData, Blob, Response } from \"node-fetch\";\n// puppeteer is lazy-loaded in captureSliceSimulatorScreenshot\nimport type { BrowserContext, Viewport } from \"puppeteer\";\n\nimport { checkIsURLAccessible } from \"../../lib/checkIsURLAccessible\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { decode } from \"../../lib/decode\";\n\nimport { S3ACL } from \"../../types\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { InternalError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nconst SLICE_SIMULATOR_WAIT_FOR_SELECTOR = \"#__iframe-ready\";\nconst SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT = 10_000; // ms\nconst SLICE_SIMULATOR_SCREENSHOT_SELECTOR = \"#__iframe-renderer\";\n\nconst DEFAULT_SCREENSHOT_VIEWPORT: Viewport = {\n\twidth: 1200,\n\theight: 800,\n};\n\nfunction assertS3ACLInitialized(\n\ts3ACL: S3ACL | undefined,\n): asserts s3ACL is NonNullable<typeof s3ACL> {\n\tif (s3ACL == undefined) {\n\t\tthrow new Error(\n\t\t\t\"An S3 ACL has not been initialized. Run `SliceMachineManager.screenshots.prototype.initS3ACL()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\nfunction assertBrowserContextInitialized(\n\tbrowserContext: BrowserContext | undefined,\n): asserts browserContext is NonNullable<typeof browserContext> {\n\tif (browserContext == undefined) {\n\t\tthrow new Error(\n\t\t\t\"A browser context has not been initialized. Run `SliceMachineManager.screenshots.prototype.initBrowserContext()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\n/**\n * Encodes a part of a Slice Simulator URL to ensure it can be added to a URL\n * safely.\n *\n * The encoding logic must match Slice Machine UI's URL encoding practices.\n * Today, that requires the following:\n *\n * - Replace \"/\" with \"--\" (e.g. a Slice Library ID of \"./slices\" should turn into\n * \".--slices\")\n *\n * @param urlPart - A part of the URL.\n *\n * @returns `urlPart` encoded for use in a URL.\n */\nconst encodeSliceSimulatorURLPart = (urlPart: string): string => {\n\treturn urlPart.replace(/\\//g, \"--\");\n};\n\ntype ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs = {\n\tsliceMachineUIOrigin: string;\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tviewport?: Viewport;\n};\n\ntype ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType = {\n\tdata: Buffer;\n};\n\ntype ScreenshotsManagerUploadScreenshotArgs = {\n\tdata: Buffer;\n\tkeyPrefix?: string;\n};\n\ntype ScreenshotsManagerUploadScreenshotReturnType = {\n\turl: string;\n};\n\ntype ScreenshotsManagerDeleteScreenshotFolderArgs = {\n\tsliceID: string;\n};\n\nexport class ScreenshotsManager extends BaseManager {\n\tprivate _browserContext: BrowserContext | undefined;\n\tprivate _s3ACL: S3ACL | undefined;\n\n\tasync initBrowserContext(): Promise<void> {\n\t\tif (this._browserContext) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet puppeteer: typeof import(\"puppeteer\");\n\t\ttry {\n\t\t\t// Lazy-load Puppeteer only once it is needed.\n\t\t\tpuppeteer = await import(\"puppeteer\");\n\t\t} catch {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Screenshots require Puppeteer but Puppeteer was not found. Check that the `puppeteer` package is installed before trying again.\",\n\t\t\t);\n\t\t}\n\n\t\tconst browser = await puppeteer.launch({ headless: \"new\" });\n\n\t\tthis._browserContext = await browser.createIncognitoBrowserContext();\n\t}\n\n\tasync initS3ACL(): Promise<void> {\n\t\tif (this._s3ACL) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst awsACLURL = new URL(\"create\", API_ENDPOINTS.AwsAclProvider);\n\t\tconst awsACLRes = await this._fetch({ url: awsACLURL });\n\n\t\tconst awsACLText = await awsACLRes.text();\n\t\tlet awsACLJSON: unknown;\n\t\ttry {\n\t\t\tawsACLJSON = JSON.parse(awsACLText);\n\t\t} catch (error) {\n\t\t\t// Response is not JSON\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid AWS ACL response from ${awsACLURL}: ${awsACLText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst { value: awsACL, error } = decode(\n\t\t\tt.intersection([\n\t\t\t\tt.type({\n\t\t\t\t\tvalues: t.type({\n\t\t\t\t\t\turl: t.string,\n\t\t\t\t\t\tfields: t.record(t.string, t.string),\n\t\t\t\t\t}),\n\t\t\t\t\timgixEndpoint: t.string,\n\t\t\t\t}),\n\t\t\t\tt.partial({\n\t\t\t\t\tmessage: t.string,\n\t\t\t\t\tMessage: t.string,\n\t\t\t\t\terror: t.string,\n\t\t\t\t}),\n\t\t\t]),\n\t\t\tawsACLJSON,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid AWS ACL response from ${awsACLURL}`);\n\t\t}\n\n\t\tconst errorMessage = awsACL.error || awsACL.message || awsACL.Message;\n\t\tif (errorMessage) {\n\t\t\tthrow new Error(`Failed to create an AWS ACL: ${errorMessage}`);\n\t\t}\n\n\t\tthis._s3ACL = {\n\t\t\tuploadEndpoint: awsACL.values.url,\n\t\t\trequiredFormDataFields: awsACL.values.fields,\n\t\t\timgixEndpoint: awsACL.imgixEndpoint,\n\t\t};\n\t}\n\n\t// TODO: Abstract to a generic `captureScreenshot()` method that is\n\t// used within a Slice-specific method in SliceManager.\n\tasync captureSliceSimulatorScreenshot(\n\t\targs: ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs,\n\t): Promise<ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType> {\n\t\tassertBrowserContextInitialized(this._browserContext);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\n\t\tif (!sliceMachineConfig.localSliceSimulatorURL) {\n\t\t\t// TODO: Provide a more helpful error message.\n\t\t\tthrow new Error(\n\t\t\t\t\"A local Slice Simulator URL must be configured in your Slice Machine configuration file.\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model } = await this.slices.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\t\tif (!model) {\n\t\t\tthrow new Error(\n\t\t\t\t`Did not find a Slice in library \"${args.libraryID}\" with ID \"${args.sliceID}\".`,\n\t\t\t);\n\t\t}\n\n\t\tconst viewport = args.viewport || DEFAULT_SCREENSHOT_VIEWPORT;\n\n\t\t// TODO: Change `model.name` to `args.sliceID`?\n\t\t// Making that change would require changing the screenshot\n\t\t// page path in Slice Machine UI.\n\t\tconst url = new URL(\n\t\t\t`./${encodeSliceSimulatorURLPart(args.libraryID)}/${model.name}/${\n\t\t\t\targs.variationID\n\t\t\t}/screenshot`,\n\t\t\targs.sliceMachineUIOrigin,\n\t\t);\n\t\turl.searchParams.set(\"screenWidth\", viewport.width.toString());\n\t\turl.searchParams.set(\"screenHeight\", viewport.height.toString());\n\n\t\tconst isURLAccessible = await checkIsURLAccessible(url.toString());\n\n\t\tif (!isURLAccessible) {\n\t\t\tthrow new Error(\n\t\t\t\t`Slice Simulator screenshot URL is not accessible: ${url}`,\n\t\t\t);\n\t\t}\n\n\t\tconst page = await this._browserContext.newPage();\n\t\tpage.setViewport(viewport);\n\n\t\tawait page.goto(url.toString(), { waitUntil: [\"load\", \"networkidle0\"] });\n\t\tawait page.waitForSelector(SLICE_SIMULATOR_WAIT_FOR_SELECTOR, {\n\t\t\ttimeout: SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT,\n\t\t});\n\n\t\tconst element = await page.$(SLICE_SIMULATOR_SCREENSHOT_SELECTOR);\n\t\tif (!element) {\n\t\t\tconst baseURL = new URL(url.pathname, url.origin);\n\n\t\t\tthrow new Error(\n\t\t\t\t`Slice Simulator did not find ${SLICE_SIMULATOR_WAIT_FOR_SELECTOR} on the page. Verify the URL is correct: ${baseURL}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await element.screenshot({\n\t\t\tencoding: \"binary\",\n\t\t\tclip: {\n\t\t\t\twidth: viewport.width,\n\t\t\t\theight: viewport.height,\n\t\t\t\tx: 0,\n\t\t\t\ty: 0,\n\t\t\t},\n\t\t})) as Buffer;\n\n\t\treturn {\n\t\t\tdata,\n\t\t};\n\t}\n\n\tasync uploadScreenshot(\n\t\targs: ScreenshotsManagerUploadScreenshotArgs,\n\t): Promise<ScreenshotsManagerUploadScreenshotReturnType> {\n\t\tassertS3ACLInitialized(this._s3ACL);\n\n\t\tconst formData = new FormData();\n\n\t\tfor (const requiredFormDataFieldKey in this._s3ACL.requiredFormDataFields) {\n\t\t\tformData.append(\n\t\t\t\trequiredFormDataFieldKey,\n\t\t\t\tthis._s3ACL.requiredFormDataFields[requiredFormDataFieldKey],\n\t\t\t);\n\t\t}\n\n\t\tconst contentDigest = createContentDigest(args.data);\n\t\tconst fileType = await fileTypeFromBuffer(args.data);\n\t\tconst fileName = fileType\n\t\t\t? `${contentDigest}.${fileType.ext}`\n\t\t\t: contentDigest;\n\t\tconst key = args.keyPrefix ? `${args.keyPrefix}/${fileName}` : fileName;\n\n\t\tformData.set(\"key\", key);\n\n\t\tif (fileType) {\n\t\t\tformData.set(\"Content-Type\", fileType.mime);\n\t\t}\n\n\t\tformData.set(\"file\", new Blob([args.data], { type: fileType?.mime }));\n\n\t\tconst res = await fetch(this._s3ACL.uploadEndpoint, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: formData,\n\t\t});\n\n\t\tif (res.ok) {\n\t\t\tconst url = new URL(key, this._s3ACL.imgixEndpoint);\n\t\t\turl.searchParams.set(\"auto\", \"compress,format\");\n\n\t\t\treturn {\n\t\t\t\turl: url.toString(),\n\t\t\t};\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to upload screenshot with status code: ${res.status}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync deleteScreenshotFolder(\n\t\targs: ScreenshotsManagerDeleteScreenshotFolderArgs,\n\t): Promise<void> {\n\t\tconst res = await this._fetch({\n\t\t\t// We're sending `args.sliceID` as `sliceName` because it's inconsistently\n\t\t\t// named in the ACL Provider API.\n\t\t\tbody: { sliceName: args.sliceID },\n\t\t\tmethod: \"POST\",\n\t\t\turl: new URL(\"delete-folder\", API_ENDPOINTS.AwsAclProvider),\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to delete screenshot folder with status code: ${res.status}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\";\n\t\tbody?: unknown;\n\t}): Promise<Response> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\n\t\treturn await fetch(args.url, {\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${authenticationToken}`,\n\t\t\t\tRepository: sliceMachineConfig.repositoryName,\n\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...(args.body ? { \"Content-Type\": \"application/json\" } : {}),\n\t\t\t},\n\t\t\tmethod: args.method,\n\t\t});\n\t}\n}\n"],"names":["BaseManager","InternalError","API_ENDPOINTS","error","decode","t","checkIsURLAccessible","FormData","createContentDigest","fileTypeFromBuffer","Blob","fetch","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,oCAAoC;AAC1C,MAAM,4CAA4C;AAClD,MAAM,sCAAsC;AAE5C,MAAM,8BAAwC;AAAA,EAC7C,OAAO;AAAA,EACP,QAAQ;;AAGT,SAAS,uBACR,OAAwB;AAExB,MAAI,SAAS,QAAW;AACjB,UAAA,IAAI,MACT,gIAAgI;AAAA,EAEjI;AACF;AAEA,SAAS,gCACR,gBAA0C;AAE1C,MAAI,kBAAkB,QAAW;AAC1B,UAAA,IAAI,MACT,iJAAiJ;AAAA,EAElJ;AACF;AAgBA,MAAM,8BAA8B,CAAC,YAA2B;AACxD,SAAA,QAAQ,QAAQ,OAAO,IAAI;AACnC;AA2BM,MAAO,2BAA2BA,YAAAA,YAAW;AAAA,EAA7C;AAAA;AACG;AACA;AAAA;AAAA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AAI,QAAQ;AAAA,IAE9D;AAAA,EACF;AAAA,EAEA,MAAM,uBACL,MAAkD;AAE5C,UAAA,MAAM,MAAM,KAAK,OAAO;AAAA;AAAA;AAAA,MAG7B,MAAM,EAAE,WAAW,KAAK,QAAS;AAAA,MACjC,QAAQ;AAAA,MACR,KAAK,IAAI,IAAI,iBAAiBT,cAAAA,cAAc,cAAc;AAAA,IAAA,CAC1D;AACG,QAAA,CAAC,IAAI,IAAI;AACZ,YAAM,IAAI,MACT,wDAAwD,IAAI,QAAQ;AAAA,IAErE;AAAA,EACF;AAAA,EAEQ,MAAM,OAAO,MAIpB;AACA,UAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAClE,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAE5D,WAAA,MAAMS,QAAAA,QAAM,KAAK,KAAK;AAAA,MAC5B,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,IAAI;AAAA,MAC9C,SAAS;AAAA,QACR,eAAe,UAAU;AAAA,QACzB,YAAY,mBAAmB;AAAA,QAC/B,cAAcC,yBAAA;AAAA,QACd,GAAI,KAAK,OAAO,EAAE,gBAAgB,uBAAuB;MACzD;AAAA,MACD,QAAQ,KAAK;AAAA,IAAA,CACb;AAAA,EACF;AACA;;"}
|
|
1
|
+
{"version":3,"file":"ScreenshotsManager.cjs","sources":["../../../../src/managers/screenshots/ScreenshotsManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport fetch, { FormData, Blob, Response } from \"node-fetch\";\n// puppeteer is lazy-loaded in captureSliceSimulatorScreenshot\nimport type { BrowserContext, Viewport } from \"puppeteer\";\n\nimport { checkIsURLAccessible } from \"../../lib/checkIsURLAccessible\";\nimport { createContentDigest } from \"../../lib/createContentDigest\";\nimport { decode } from \"../../lib/decode\";\n\nimport { S3ACL } from \"../../types\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../../constants/SLICE_MACHINE_USER_AGENT\";\nimport { API_ENDPOINTS } from \"../../constants/API_ENDPOINTS\";\nimport { InternalError } from \"../../errors\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nconst SLICE_SIMULATOR_WAIT_FOR_SELECTOR = \"#__iframe-ready\";\nconst SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT = 10_000; // ms\nconst SLICE_SIMULATOR_SCREENSHOT_SELECTOR = \"#__iframe-renderer\";\n\nconst DEFAULT_SCREENSHOT_VIEWPORT: Viewport = {\n\twidth: 1200,\n\theight: 800,\n};\n\nfunction assertS3ACLInitialized(\n\ts3ACL: S3ACL | undefined,\n): asserts s3ACL is NonNullable<typeof s3ACL> {\n\tif (s3ACL == undefined) {\n\t\tthrow new Error(\n\t\t\t\"An S3 ACL has not been initialized. Run `SliceMachineManager.screenshots.prototype.initS3ACL()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\nfunction assertBrowserContextInitialized(\n\tbrowserContext: BrowserContext | undefined,\n): asserts browserContext is NonNullable<typeof browserContext> {\n\tif (browserContext == undefined) {\n\t\tthrow new Error(\n\t\t\t\"A browser context has not been initialized. Run `SliceMachineManager.screenshots.prototype.initBrowserContext()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\n/**\n * Encodes a part of a Slice Simulator URL to ensure it can be added to a URL\n * safely.\n *\n * The encoding logic must match Slice Machine UI's URL encoding practices.\n * Today, that requires the following:\n *\n * - Replace \"/\" with \"--\" (e.g. a Slice Library ID of \"./slices\" should turn into\n * \".--slices\")\n *\n * @param urlPart - A part of the URL.\n *\n * @returns `urlPart` encoded for use in a URL.\n */\nconst encodeSliceSimulatorURLPart = (urlPart: string): string => {\n\treturn urlPart.replace(/\\//g, \"--\");\n};\n\ntype ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs = {\n\tsliceMachineUIOrigin: string;\n\tlibraryID: string;\n\tsliceID: string;\n\tvariationID: string;\n\tviewport?: Viewport;\n};\n\ntype ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType = {\n\tdata: Buffer;\n};\n\ntype ScreenshotsManagerUploadScreenshotArgs = {\n\tdata: Buffer;\n\tkeyPrefix?: string;\n};\n\ntype ScreenshotsManagerUploadScreenshotReturnType = {\n\turl: string;\n};\n\ntype ScreenshotsManagerDeleteScreenshotFolderArgs = {\n\tsliceID: string;\n};\n\nexport class ScreenshotsManager extends BaseManager {\n\tprivate _browserContext: BrowserContext | undefined;\n\tprivate _s3ACL: S3ACL | undefined;\n\n\tasync initBrowserContext(): Promise<void> {\n\t\tif (this._browserContext) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet puppeteer: typeof import(\"puppeteer\");\n\t\ttry {\n\t\t\t// Lazy-load Puppeteer only once it is needed.\n\t\t\tpuppeteer = await import(\"puppeteer\");\n\t\t} catch {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Screenshots require Puppeteer but Puppeteer was not found. Check that the `puppeteer` package is installed before trying again.\",\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tconst browser = await puppeteer.launch({ headless: \"new\" });\n\n\t\t\tthis._browserContext = await browser.createIncognitoBrowserContext();\n\t\t} catch (error) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Error launching browser. If you're using an Apple Silicon Mac, check if Rosetta is installed.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tasync initS3ACL(): Promise<void> {\n\t\t// TODO: we need to find a way to create a new AWS ACL only when necessary (e.g., when it has expired).\n\t\t// if (this._s3ACL) {\n\t\t// \treturn;\n\t\t// }\n\n\t\tconst awsACLURL = new URL(\"create\", API_ENDPOINTS.AwsAclProvider);\n\t\tconst awsACLRes = await this._fetch({ url: awsACLURL });\n\n\t\tconst awsACLText = await awsACLRes.text();\n\t\tlet awsACLJSON: unknown;\n\t\ttry {\n\t\t\tawsACLJSON = JSON.parse(awsACLText);\n\t\t} catch (error) {\n\t\t\t// Response is not JSON\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid AWS ACL response from ${awsACLURL}: ${awsACLText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst { value: awsACL, error } = decode(\n\t\t\tt.intersection([\n\t\t\t\tt.type({\n\t\t\t\t\tvalues: t.type({\n\t\t\t\t\t\turl: t.string,\n\t\t\t\t\t\tfields: t.record(t.string, t.string),\n\t\t\t\t\t}),\n\t\t\t\t\timgixEndpoint: t.string,\n\t\t\t\t}),\n\t\t\t\tt.partial({\n\t\t\t\t\tmessage: t.string,\n\t\t\t\t\tMessage: t.string,\n\t\t\t\t\terror: t.string,\n\t\t\t\t}),\n\t\t\t]),\n\t\t\tawsACLJSON,\n\t\t);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid AWS ACL response from ${awsACLURL}`);\n\t\t}\n\n\t\tconst errorMessage = awsACL.error || awsACL.message || awsACL.Message;\n\t\tif (errorMessage) {\n\t\t\tthrow new Error(`Failed to create an AWS ACL: ${errorMessage}`);\n\t\t}\n\n\t\tthis._s3ACL = {\n\t\t\tuploadEndpoint: awsACL.values.url,\n\t\t\trequiredFormDataFields: awsACL.values.fields,\n\t\t\timgixEndpoint: awsACL.imgixEndpoint,\n\t\t};\n\t}\n\n\t// TODO: Abstract to a generic `captureScreenshot()` method that is\n\t// used within a Slice-specific method in SliceManager.\n\tasync captureSliceSimulatorScreenshot(\n\t\targs: ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs,\n\t): Promise<ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType> {\n\t\tassertBrowserContextInitialized(this._browserContext);\n\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\n\t\tif (!sliceMachineConfig.localSliceSimulatorURL) {\n\t\t\t// TODO: Provide a more helpful error message.\n\t\t\tthrow new Error(\n\t\t\t\t\"A local Slice Simulator URL must be configured in your Slice Machine configuration file.\",\n\t\t\t);\n\t\t}\n\n\t\tconst { model } = await this.slices.readSlice({\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\t\tif (!model) {\n\t\t\tthrow new Error(\n\t\t\t\t`Did not find a Slice in library \"${args.libraryID}\" with ID \"${args.sliceID}\".`,\n\t\t\t);\n\t\t}\n\n\t\tconst viewport = args.viewport || DEFAULT_SCREENSHOT_VIEWPORT;\n\n\t\t// TODO: Change `model.name` to `args.sliceID`?\n\t\t// Making that change would require changing the screenshot\n\t\t// page path in Slice Machine UI.\n\t\tconst url = new URL(\n\t\t\t`./${encodeSliceSimulatorURLPart(args.libraryID)}/${model.name}/${\n\t\t\t\targs.variationID\n\t\t\t}/screenshot`,\n\t\t\targs.sliceMachineUIOrigin,\n\t\t);\n\t\turl.searchParams.set(\"screenWidth\", viewport.width.toString());\n\t\turl.searchParams.set(\"screenHeight\", viewport.height.toString());\n\n\t\tconst isURLAccessible = await checkIsURLAccessible(url.toString());\n\n\t\tif (!isURLAccessible) {\n\t\t\tthrow new Error(\n\t\t\t\t`Slice Simulator screenshot URL is not accessible: ${url}`,\n\t\t\t);\n\t\t}\n\n\t\tconst page = await this._browserContext.newPage();\n\t\tpage.setViewport(viewport);\n\n\t\tawait page.goto(url.toString(), { waitUntil: [\"load\", \"networkidle0\"] });\n\t\tawait page.waitForSelector(SLICE_SIMULATOR_WAIT_FOR_SELECTOR, {\n\t\t\ttimeout: SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT,\n\t\t});\n\n\t\tconst element = await page.$(SLICE_SIMULATOR_SCREENSHOT_SELECTOR);\n\t\tif (!element) {\n\t\t\tconst baseURL = new URL(url.pathname, url.origin);\n\n\t\t\tthrow new Error(\n\t\t\t\t`Slice Simulator did not find ${SLICE_SIMULATOR_WAIT_FOR_SELECTOR} on the page. Verify the URL is correct: ${baseURL}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await element.screenshot({\n\t\t\tencoding: \"binary\",\n\t\t\tclip: {\n\t\t\t\twidth: viewport.width,\n\t\t\t\theight: viewport.height,\n\t\t\t\tx: 0,\n\t\t\t\ty: 0,\n\t\t\t},\n\t\t})) as Buffer;\n\n\t\treturn {\n\t\t\tdata,\n\t\t};\n\t}\n\n\tasync uploadScreenshot(\n\t\targs: ScreenshotsManagerUploadScreenshotArgs,\n\t): Promise<ScreenshotsManagerUploadScreenshotReturnType> {\n\t\tassertS3ACLInitialized(this._s3ACL);\n\n\t\tconst formData = new FormData();\n\n\t\tfor (const requiredFormDataFieldKey in this._s3ACL.requiredFormDataFields) {\n\t\t\tformData.append(\n\t\t\t\trequiredFormDataFieldKey,\n\t\t\t\tthis._s3ACL.requiredFormDataFields[requiredFormDataFieldKey],\n\t\t\t);\n\t\t}\n\n\t\tconst contentDigest = createContentDigest(args.data);\n\t\tconst fileType = await fileTypeFromBuffer(args.data);\n\t\tconst fileName = fileType\n\t\t\t? `${contentDigest}.${fileType.ext}`\n\t\t\t: contentDigest;\n\t\tconst key = args.keyPrefix ? `${args.keyPrefix}/${fileName}` : fileName;\n\n\t\tformData.set(\"key\", key);\n\n\t\tif (fileType) {\n\t\t\tformData.set(\"Content-Type\", fileType.mime);\n\t\t}\n\n\t\tformData.set(\"file\", new Blob([args.data], { type: fileType?.mime }));\n\n\t\tconst res = await fetch(this._s3ACL.uploadEndpoint, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: formData,\n\t\t});\n\n\t\tif (res.ok) {\n\t\t\tconst url = new URL(key, this._s3ACL.imgixEndpoint);\n\t\t\turl.searchParams.set(\"auto\", \"compress,format\");\n\n\t\t\treturn {\n\t\t\t\turl: url.toString(),\n\t\t\t};\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to upload screenshot with status code: ${res.status}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync deleteScreenshotFolder(\n\t\targs: ScreenshotsManagerDeleteScreenshotFolderArgs,\n\t): Promise<void> {\n\t\tconst res = await this._fetch({\n\t\t\t// We're sending `args.sliceID` as `sliceName` because it's inconsistently\n\t\t\t// named in the ACL Provider API.\n\t\t\tbody: { sliceName: args.sliceID },\n\t\t\tmethod: \"POST\",\n\t\t\turl: new URL(\"delete-folder\", API_ENDPOINTS.AwsAclProvider),\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to delete screenshot folder with status code: ${res.status}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async _fetch(args: {\n\t\turl: URL;\n\t\tmethod?: \"GET\" | \"POST\";\n\t\tbody?: unknown;\n\t}): Promise<Response> {\n\t\tconst authenticationToken = await this.user.getAuthenticationToken();\n\t\tconst sliceMachineConfig = await this.project.getSliceMachineConfig();\n\n\t\treturn await fetch(args.url, {\n\t\t\tbody: args.body ? JSON.stringify(args.body) : undefined,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${authenticationToken}`,\n\t\t\t\tRepository: sliceMachineConfig.repositoryName,\n\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t...(args.body ? { \"Content-Type\": \"application/json\" } : {}),\n\t\t\t},\n\t\t\tmethod: args.method,\n\t\t});\n\t}\n}\n"],"names":["BaseManager","InternalError","API_ENDPOINTS","error","decode","t","checkIsURLAccessible","FormData","createContentDigest","fileTypeFromBuffer","Blob","fetch","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,oCAAoC;AAC1C,MAAM,4CAA4C;AAClD,MAAM,sCAAsC;AAE5C,MAAM,8BAAwC;AAAA,EAC7C,OAAO;AAAA,EACP,QAAQ;;AAGT,SAAS,uBACR,OAAwB;AAExB,MAAI,SAAS,QAAW;AACjB,UAAA,IAAI,MACT,gIAAgI;AAAA,EAEjI;AACF;AAEA,SAAS,gCACR,gBAA0C;AAE1C,MAAI,kBAAkB,QAAW;AAC1B,UAAA,IAAI,MACT,iJAAiJ;AAAA,EAElJ;AACF;AAgBA,MAAM,8BAA8B,CAAC,YAA2B;AACxD,SAAA,QAAQ,QAAQ,OAAO,IAAI;AACnC;AA2BM,MAAO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