@slicemachine/manager 0.15.3-dev-next-release.2 → 0.15.3-dev-next-release.3

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.
@@ -24,8 +24,7 @@ const omitProcedures = defineOmits()([
24
24
  "documentation._sliceMachineManager",
25
25
  "sliceTemplateLibrary._sliceMachineManager",
26
26
  "getSliceMachinePluginRunner",
27
- "getPrismicAuthManager",
28
- "screenshots.browserContext"
27
+ "getPrismicAuthManager"
29
28
  ]);
30
29
  const getSliceMachineManagerProcedures = (args) => {
31
30
  return proceduresFromInstance.proceduresFromInstance(args.sliceMachineManager, {
@@ -1 +1 @@
1
- {"version":3,"file":"createSliceMachineManagerMiddleware.cjs","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"sliceTemplateLibrary._sliceMachineManager\",\n\t\"getSliceMachinePluginRunner\",\n\t\"getPrismicAuthManager\",\n\t\"screenshots.browserContext\",\n]);\n\nexport type SliceMachineManagerMiddleware = RPCMiddleware<\n\tProceduresFromInstance<SliceMachineManager, (typeof omitProcedures)[number]>\n>;\n\nexport type SliceMachineManagerProcedures =\n\tExtractProcedures<SliceMachineManagerMiddleware>;\n\ntype GetSliceMachineManagerProceduresArgs = {\n\tsliceMachineManager: SliceMachineManager;\n};\n\nexport const getSliceMachineManagerProcedures = (\n\targs: GetSliceMachineManagerProceduresArgs,\n): SliceMachineManagerProcedures => {\n\treturn proceduresFromInstance(args.sliceMachineManager, {\n\t\tomit: omitProcedures,\n\t});\n};\n\nexport type CreateSliceMachineManagerMiddlewareArgs = {\n\tsliceMachineManager: SliceMachineManager;\n\tonError?: OnErrorEventHandler;\n};\n\nexport const createSliceMachineManagerMiddleware = (\n\targs: CreateSliceMachineManagerMiddlewareArgs,\n): SliceMachineManagerMiddleware => {\n\treturn createRPCMiddleware({\n\t\tprocedures: getSliceMachineManagerProcedures({\n\t\t\tsliceMachineManager: args.sliceMachineManager,\n\t\t}),\n\t\tonError: args.onError,\n\t});\n};\n"],"names":["proceduresFromInstance","createRPCMiddleware"],"mappings":";;;;AAYA,MAAM,cAAc,MAAW;AAG9B,SAAO,CACN,SAC8D;AACvD,WAAA;AAAA,EAAA;AAET;AAGA,MAAM,iBAAiB,cAAmC;AAAA,EACzD;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACA,CAAA;AAaY,MAAA,mCAAmC,CAC/C,SACkC;AAC3B,SAAAA,uBAAA,uBAAuB,KAAK,qBAAqB;AAAA,IACvD,MAAM;AAAA,EAAA,CACN;AACF;AAOa,MAAA,sCAAsC,CAClD,SACkC;AAClC,SAAOC,wCAAoB;AAAA,IAC1B,YAAY,iCAAiC;AAAA,MAC5C,qBAAqB,KAAK;AAAA,IAAA,CAC1B;AAAA,IACD,SAAS,KAAK;AAAA,EAAA,CACd;AACF;;;"}
1
+ {"version":3,"file":"createSliceMachineManagerMiddleware.cjs","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"sliceTemplateLibrary._sliceMachineManager\",\n\t\"getSliceMachinePluginRunner\",\n\t\"getPrismicAuthManager\",\n]);\n\nexport type SliceMachineManagerMiddleware = RPCMiddleware<\n\tProceduresFromInstance<SliceMachineManager, (typeof omitProcedures)[number]>\n>;\n\nexport type SliceMachineManagerProcedures =\n\tExtractProcedures<SliceMachineManagerMiddleware>;\n\ntype GetSliceMachineManagerProceduresArgs = {\n\tsliceMachineManager: SliceMachineManager;\n};\n\nexport const getSliceMachineManagerProcedures = (\n\targs: GetSliceMachineManagerProceduresArgs,\n): SliceMachineManagerProcedures => {\n\treturn proceduresFromInstance(args.sliceMachineManager, {\n\t\tomit: omitProcedures,\n\t});\n};\n\nexport type CreateSliceMachineManagerMiddlewareArgs = {\n\tsliceMachineManager: SliceMachineManager;\n\tonError?: OnErrorEventHandler;\n};\n\nexport const createSliceMachineManagerMiddleware = (\n\targs: CreateSliceMachineManagerMiddlewareArgs,\n): SliceMachineManagerMiddleware => {\n\treturn createRPCMiddleware({\n\t\tprocedures: getSliceMachineManagerProcedures({\n\t\t\tsliceMachineManager: args.sliceMachineManager,\n\t\t}),\n\t\tonError: args.onError,\n\t});\n};\n"],"names":["proceduresFromInstance","createRPCMiddleware"],"mappings":";;;;AAYA,MAAM,cAAc,MAAW;AAG9B,SAAO,CACN,SAC8D;AACvD,WAAA;AAAA,EAAA;AAET;AAGA,MAAM,iBAAiB,cAAmC;AAAA,EACzD;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACA,CAAA;AAaY,MAAA,mCAAmC,CAC/C,SACkC;AAC3B,SAAAA,uBAAA,uBAAuB,KAAK,qBAAqB;AAAA,IACvD,MAAM;AAAA,EAAA,CACN;AACF;AAOa,MAAA,sCAAsC,CAClD,SACkC;AAClC,SAAOC,wCAAoB;AAAA,IAC1B,YAAY,iCAAiC;AAAA,MAC5C,qBAAqB,KAAK;AAAA,IAAA,CAC1B;AAAA,IACD,SAAS,KAAK;AAAA,EAAA,CACd;AACF;;;"}
@@ -22,8 +22,7 @@ const omitProcedures = defineOmits()([
22
22
  "documentation._sliceMachineManager",
23
23
  "sliceTemplateLibrary._sliceMachineManager",
24
24
  "getSliceMachinePluginRunner",
25
- "getPrismicAuthManager",
26
- "screenshots.browserContext"
25
+ "getPrismicAuthManager"
27
26
  ]);
28
27
  const getSliceMachineManagerProcedures = (args) => {
29
28
  return proceduresFromInstance(args.sliceMachineManager, {
@@ -1 +1 @@
1
- {"version":3,"file":"createSliceMachineManagerMiddleware.js","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"sliceTemplateLibrary._sliceMachineManager\",\n\t\"getSliceMachinePluginRunner\",\n\t\"getPrismicAuthManager\",\n\t\"screenshots.browserContext\",\n]);\n\nexport type SliceMachineManagerMiddleware = RPCMiddleware<\n\tProceduresFromInstance<SliceMachineManager, (typeof omitProcedures)[number]>\n>;\n\nexport type SliceMachineManagerProcedures =\n\tExtractProcedures<SliceMachineManagerMiddleware>;\n\ntype GetSliceMachineManagerProceduresArgs = {\n\tsliceMachineManager: SliceMachineManager;\n};\n\nexport const getSliceMachineManagerProcedures = (\n\targs: GetSliceMachineManagerProceduresArgs,\n): SliceMachineManagerProcedures => {\n\treturn proceduresFromInstance(args.sliceMachineManager, {\n\t\tomit: omitProcedures,\n\t});\n};\n\nexport type CreateSliceMachineManagerMiddlewareArgs = {\n\tsliceMachineManager: SliceMachineManager;\n\tonError?: OnErrorEventHandler;\n};\n\nexport const createSliceMachineManagerMiddleware = (\n\targs: CreateSliceMachineManagerMiddlewareArgs,\n): SliceMachineManagerMiddleware => {\n\treturn createRPCMiddleware({\n\t\tprocedures: getSliceMachineManagerProcedures({\n\t\t\tsliceMachineManager: args.sliceMachineManager,\n\t\t}),\n\t\tonError: args.onError,\n\t});\n};\n"],"names":[],"mappings":";;AAYA,MAAM,cAAc,MAAW;AAG9B,SAAO,CACN,SAC8D;AACvD,WAAA;AAAA,EAAA;AAET;AAGA,MAAM,iBAAiB,cAAmC;AAAA,EACzD;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACA,CAAA;AAaY,MAAA,mCAAmC,CAC/C,SACkC;AAC3B,SAAA,uBAAuB,KAAK,qBAAqB;AAAA,IACvD,MAAM;AAAA,EAAA,CACN;AACF;AAOa,MAAA,sCAAsC,CAClD,SACkC;AAClC,SAAO,oBAAoB;AAAA,IAC1B,YAAY,iCAAiC;AAAA,MAC5C,qBAAqB,KAAK;AAAA,IAAA,CAC1B;AAAA,IACD,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
1
+ {"version":3,"file":"createSliceMachineManagerMiddleware.js","sources":["../../../src/managers/createSliceMachineManagerMiddleware.ts"],"sourcesContent":["import {\n\tExtractProcedures,\n\tOmittableProcedures,\n\tProceduresFromInstance,\n\tRPCMiddleware,\n\tcreateRPCMiddleware,\n\tproceduresFromInstance,\n\tOnErrorEventHandler,\n} from \"r19\";\n\nimport { SliceMachineManager } from \"./SliceMachineManager\";\n\nconst defineOmits = <TObj>() => {\n\t// TODO: Change this to a nicer API. Maybe return an object with a named method (e.g. `compute`)\n\n\treturn <TOmitPaths extends string>(\n\t\tomit: readonly TOmitPaths[] | readonly OmittableProcedures<TObj>[],\n\t): readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[] => {\n\t\treturn omit as readonly Extract<TOmitPaths, OmittableProcedures<TObj>>[];\n\t};\n};\n\n// TODO: Support wildcard omits that support \"*._sliceMachineManager\"\nconst omitProcedures = defineOmits<SliceMachineManager>()([\n\t\"_sliceMachinePluginRunner\",\n\t\"_prismicAuthManager\",\n\n\t\"customTypes._sliceMachineManager\",\n\t\"plugins._sliceMachineManager\",\n\t\"prismicRepository._sliceMachineManager\",\n\t\"project._sliceMachineManager\",\n\t\"screenshots._sliceMachineManager\",\n\t\"simulator._sliceMachineManager\",\n\t\"slices._sliceMachineManager\",\n\t\"snippets._sliceMachineManager\",\n\t\"telemetry._sliceMachineManager\",\n\t\"user._sliceMachineManager\",\n\t\"versions._sliceMachineManager\",\n\t\"documentation._sliceMachineManager\",\n\t\"sliceTemplateLibrary._sliceMachineManager\",\n\t\"getSliceMachinePluginRunner\",\n\t\"getPrismicAuthManager\",\n]);\n\nexport type SliceMachineManagerMiddleware = RPCMiddleware<\n\tProceduresFromInstance<SliceMachineManager, (typeof omitProcedures)[number]>\n>;\n\nexport type SliceMachineManagerProcedures =\n\tExtractProcedures<SliceMachineManagerMiddleware>;\n\ntype GetSliceMachineManagerProceduresArgs = {\n\tsliceMachineManager: SliceMachineManager;\n};\n\nexport const getSliceMachineManagerProcedures = (\n\targs: GetSliceMachineManagerProceduresArgs,\n): SliceMachineManagerProcedures => {\n\treturn proceduresFromInstance(args.sliceMachineManager, {\n\t\tomit: omitProcedures,\n\t});\n};\n\nexport type CreateSliceMachineManagerMiddlewareArgs = {\n\tsliceMachineManager: SliceMachineManager;\n\tonError?: OnErrorEventHandler;\n};\n\nexport const createSliceMachineManagerMiddleware = (\n\targs: CreateSliceMachineManagerMiddlewareArgs,\n): SliceMachineManagerMiddleware => {\n\treturn createRPCMiddleware({\n\t\tprocedures: getSliceMachineManagerProcedures({\n\t\t\tsliceMachineManager: args.sliceMachineManager,\n\t\t}),\n\t\tonError: args.onError,\n\t});\n};\n"],"names":[],"mappings":";;AAYA,MAAM,cAAc,MAAW;AAG9B,SAAO,CACN,SAC8D;AACvD,WAAA;AAAA,EAAA;AAET;AAGA,MAAM,iBAAiB,cAAmC;AAAA,EACzD;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACA,CAAA;AAaY,MAAA,mCAAmC,CAC/C,SACkC;AAC3B,SAAA,uBAAuB,KAAK,qBAAqB;AAAA,IACvD,MAAM;AAAA,EAAA,CACN;AACF;AAOa,MAAA,sCAAsC,CAClD,SACkC;AAClC,SAAO,oBAAoB;AAAA,IAC1B,YAAY,iCAAiC;AAAA,MAC5C,qBAAqB,KAAK;AAAA,IAAA,CAC1B;AAAA,IACD,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
@@ -11,7 +11,6 @@ require("readable-web-to-node-stream");
11
11
  const core = require('./../../_node_modules/file-type/core.cjs');
12
12
  const index = require('./../../_node_modules/p-limit/index.cjs');
13
13
  const fetch = require("../../lib/fetch.cjs");
14
- const checkIsURLAccessible = require("../../lib/checkIsURLAccessible.cjs");
15
14
  const createContentDigest = require("../../lib/createContentDigest.cjs");
16
15
  const decode = require("../../lib/decode.cjs");
17
16
  const SLICE_MACHINE_USER_AGENT = require("../../constants/SLICE_MACHINE_USER_AGENT.cjs");
@@ -44,35 +43,17 @@ function _interopNamespaceDefault(e) {
44
43
  return Object.freeze(n);
45
44
  }
46
45
  const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
47
- const SLICE_SIMULATOR_WAIT_FOR_SELECTOR = "#__iframe-ready";
48
- const SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT = 1e4;
49
- const SLICE_SIMULATOR_SCREENSHOT_SELECTOR = "#__iframe-renderer";
50
- const DEFAULT_SCREENSHOT_VIEWPORT = {
51
- width: 1200,
52
- height: 800
53
- };
54
46
  function assertS3ACLInitialized(s3ACL) {
55
47
  if (s3ACL == void 0) {
56
48
  throw new Error("An S3 ACL has not been initialized. Run `SliceMachineManager.screenshots.prototype.initS3ACL()` before re-calling this method.");
57
49
  }
58
50
  }
59
- function assertBrowserContextInitialized(browserContext) {
60
- if (browserContext == void 0) {
61
- throw new Error("A browser context has not been initialized. Run `SliceMachineManager.screenshots.prototype.initBrowserContext()` before re-calling this method.");
62
- }
63
- }
64
51
  const uploadScreenshotLimit = index(10);
65
- const encodeSliceSimulatorURLPart = (urlPart) => {
66
- return urlPart.replace(/\//g, "--");
67
- };
68
52
  class ScreenshotsManager extends BaseManager.BaseManager {
69
53
  constructor() {
70
54
  super(...arguments);
71
- __publicField(this, "_browserContext");
72
55
  __publicField(this, "_s3ACL");
73
56
  }
74
- async initBrowserContext() {
75
- }
76
57
  async initS3ACL() {
77
58
  const awsACLURL = new URL("create", API_ENDPOINTS.API_ENDPOINTS.AwsAclProvider);
78
59
  const awsACLRes = await this._fetch({ url: awsACLURL });
@@ -116,53 +97,6 @@ class ScreenshotsManager extends BaseManager.BaseManager {
116
97
  imgixEndpoint: awsACL.imgixEndpoint
117
98
  };
118
99
  }
119
- // TODO: Abstract to a generic `captureScreenshot()` method that is
120
- // used within a Slice-specific method in SliceManager.
121
- async captureSliceSimulatorScreenshot(args) {
122
- assertBrowserContextInitialized(this._browserContext);
123
- const sliceMachineConfig = await this.project.getSliceMachineConfig();
124
- if (!sliceMachineConfig.localSliceSimulatorURL) {
125
- throw new Error("A local Slice Simulator URL must be configured in your Slice Machine configuration file.");
126
- }
127
- const { model } = await this.slices.readSlice({
128
- libraryID: args.libraryID,
129
- sliceID: args.sliceID
130
- });
131
- if (!model) {
132
- throw new Error(`Did not find a Slice in library "${args.libraryID}" with ID "${args.sliceID}".`);
133
- }
134
- const viewport = args.viewport || DEFAULT_SCREENSHOT_VIEWPORT;
135
- const url = new URL(`./${encodeSliceSimulatorURLPart(args.libraryID)}/${model.name}/${args.variationID}/screenshot`, args.sliceMachineUIOrigin);
136
- url.searchParams.set("screenWidth", viewport.width.toString());
137
- url.searchParams.set("screenHeight", viewport.height.toString());
138
- const isURLAccessible = await checkIsURLAccessible.checkIsURLAccessible(url.toString());
139
- if (!isURLAccessible) {
140
- throw new Error(`Slice Simulator screenshot URL is not accessible: ${url}`);
141
- }
142
- const page = await this._browserContext.newPage();
143
- page.setViewport(viewport);
144
- await page.goto(url.toString(), { waitUntil: ["load", "networkidle0"] });
145
- await page.waitForSelector(SLICE_SIMULATOR_WAIT_FOR_SELECTOR, {
146
- timeout: SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT
147
- });
148
- const element = await page.$(SLICE_SIMULATOR_SCREENSHOT_SELECTOR);
149
- if (!element) {
150
- const baseURL = new URL(url.pathname, url.origin);
151
- throw new Error(`Slice Simulator did not find ${SLICE_SIMULATOR_WAIT_FOR_SELECTOR} on the page. Verify the URL is correct: ${baseURL}`);
152
- }
153
- const data = await element.screenshot({
154
- encoding: "binary",
155
- clip: {
156
- width: viewport.width,
157
- height: viewport.height,
158
- x: 0,
159
- y: 0
160
- }
161
- });
162
- return {
163
- data
164
- };
165
- }
166
100
  async uploadScreenshot(args) {
167
101
  assertS3ACLInitialized(this._s3ACL);
168
102
  const formData = new esm_min.FormData();
@@ -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 pLimit from \"p-limit\";\nimport fetch, { FormData, Blob, Response } from \"../../lib/fetch\";\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\";\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\n// TODO(DT-1534): Use Puppeteer types if we want reactive Puppeteer screenshots\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Viewport = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype BrowserContext = any;\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\nconst uploadScreenshotLimit = pLimit(10);\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\t// TODO(DT-1534): Uncomment to enable Puppeteer screenshots or delete if we decide to remove Puppeteer\n\t\t//\n\t\t// if (this._browserContext) {\n\t\t// \treturn;\n\t\t// }\n\t\t//\n\t\t// let puppeteer: typeof import(\"puppeteer\");\n\t\t// try {\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\t\t// try {\n\t\t// \tconst browser = await puppeteer.launch({ headless: \"new\" });\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\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\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\t\tcause: error,\n\t\t\t});\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\t\tcause: error,\n\t\t\t});\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 s3ACLEndpoint = this._s3ACL.uploadEndpoint;\n\t\tconst res = await uploadScreenshotLimit(() =>\n\t\t\tfetch(s3ACLEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t}),\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\tconst text = await res.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to upload screenshot with status code: ${res.status}`,\n\t\t\t\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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\tconst text = await res.text();\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\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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":["pLimit","BaseManager","API_ENDPOINTS","error","decode","t","checkIsURLAccessible","FormData","createContentDigest","fileTypeFromBuffer","Blob","fetch","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,oCAAoC;AAC1C,MAAM,4CAA4C;AAClD,MAAM,sCAAsC;AAQ5C,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;AAEA,MAAM,wBAAwBA,MAAO,EAAE;AAgBvC,MAAM,8BAA8B,CAAC,YAA2B;AACxD,SAAA,QAAQ,QAAQ,OAAO,IAAI;AACnC;AA2BM,MAAO,2BAA2BC,YAAAA,YAAW;AAAA,EAA7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,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;AACN,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,wDAAwD,IAAI,UAC5D;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,MAAM,OAAO,MAIpB;AACA,UAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAClE,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAE5D,WAAA,MAAMS,MAAAA,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 pLimit from \"p-limit\";\nimport fetch, { FormData, Blob, Response } from \"../../lib/fetch\";\n\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\";\n\nimport { BaseManager } from \"../BaseManager\";\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\nconst uploadScreenshotLimit = pLimit(10);\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 _s3ACL: S3ACL | undefined;\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\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\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\t\tcause: error,\n\t\t\t});\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\t\tcause: error,\n\t\t\t});\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\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 s3ACLEndpoint = this._s3ACL.uploadEndpoint;\n\t\tconst res = await uploadScreenshotLimit(() =>\n\t\t\tfetch(s3ACLEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t}),\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\tconst text = await res.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to upload screenshot with status code: ${res.status}`,\n\t\t\t\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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\tconst text = await res.text();\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\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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":["pLimit","BaseManager","API_ENDPOINTS","error","decode","t","FormData","createContentDigest","fileTypeFromBuffer","Blob","fetch","SLICE_MACHINE_USER_AGENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,uBACR,OAAwB;AAExB,MAAI,SAAS,QAAW;AACjB,UAAA,IAAI,MACT,gIAAgI;AAAA,EAEjI;AACF;AAEA,MAAM,wBAAwBA,MAAO,EAAE;AAejC,MAAO,2BAA2BC,YAAAA,YAAW;AAAA,EAA7C;AAAA;AACG;AAAA;AAAA,EAER,MAAM,YAAS;AAMd,UAAM,YAAY,IAAI,IAAI,UAAUC,4BAAc,cAAc;AAChE,UAAM,YAAY,MAAM,KAAK,OAAO,EAAE,KAAK,WAAW;AAEhD,UAAA,aAAa,MAAM,UAAU;AAC/B,QAAA;AACA,QAAA;AACU,mBAAA,KAAK,MAAM,UAAU;AAAA,aAC1BC;AAER,YAAM,IAAI,MACT,iCAAiC,cAAc,cAC/C;AAAA,QACC,OAAOA;AAAAA,MAAA,CACP;AAAA,IAEF;AAED,UAAM,EAAE,OAAO,QAAQ,MAAU,IAAAC,OAAA,OAChCC,aAAE,aAAa;AAAA,MACdA,aAAE,KAAK;AAAA,QACN,QAAQA,aAAE,KAAK;AAAA,UACd,KAAKA,aAAE;AAAA,UACP,QAAQA,aAAE,OAAOA,aAAE,QAAQA,aAAE,MAAM;AAAA,QAAA,CACnC;AAAA,QACD,eAAeA,aAAE;AAAA,MAAA,CACjB;AAAA,MACDA,aAAE,QAAQ;AAAA,QACT,SAASA,aAAE;AAAA,QACX,SAASA,aAAE;AAAA,QACX,OAAOA,aAAE;AAAA,MAAA,CACT;AAAA,IAAA,CACD,GACD,UAAU;AAGX,QAAI,OAAO;AACJ,YAAA,IAAI,MAAM,iCAAiC,aAAa;AAAA,QAC7D,OAAO;AAAA,MAAA,CACP;AAAA,IACD;AAED,UAAM,eAA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AA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,iDAAiD,IAAI,UACrD;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;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,iBAAiBR,cAAAA,cAAc,cAAc;AAAA,IAAA,CAC1D;AACG,QAAA,CAAC,IAAI,IAAI;AACN,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,wDAAwD,IAAI,UAC5D;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,MAAM,OAAO,MAIpB;AACA,UAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAClE,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAE5D,WAAA,MAAMQ,MAAAA,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,16 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { BaseManager } from "../BaseManager";
3
- type Viewport = any;
4
- type ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs = {
5
- sliceMachineUIOrigin: string;
6
- libraryID: string;
7
- sliceID: string;
8
- variationID: string;
9
- viewport?: Viewport;
10
- };
11
- type ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType = {
12
- data: Buffer;
13
- };
14
3
  type ScreenshotsManagerUploadScreenshotArgs = {
15
4
  data: Buffer;
16
5
  keyPrefix?: string;
@@ -22,11 +11,8 @@ type ScreenshotsManagerDeleteScreenshotFolderArgs = {
22
11
  sliceID: string;
23
12
  };
24
13
  export declare class ScreenshotsManager extends BaseManager {
25
- private _browserContext;
26
14
  private _s3ACL;
27
- initBrowserContext(): Promise<void>;
28
15
  initS3ACL(): Promise<void>;
29
- captureSliceSimulatorScreenshot(args: ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs): Promise<ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType>;
30
16
  uploadScreenshot(args: ScreenshotsManagerUploadScreenshotArgs): Promise<ScreenshotsManagerUploadScreenshotReturnType>;
31
17
  deleteScreenshotFolder(args: ScreenshotsManagerDeleteScreenshotFolderArgs): Promise<void>;
32
18
  private _fetch;
@@ -9,7 +9,6 @@ import "readable-web-to-node-stream";
9
9
  import { fileTypeFromBuffer } from './../../_node_modules/file-type/core.js';
10
10
  import pLimit from './../../_node_modules/p-limit/index.js';
11
11
  import fetch from "../../lib/fetch.js";
12
- import { checkIsURLAccessible } from "../../lib/checkIsURLAccessible.js";
13
12
  import { createContentDigest } from "../../lib/createContentDigest.js";
14
13
  import { decode } from "../../lib/decode.js";
15
14
  import { SLICE_MACHINE_USER_AGENT } from "../../constants/SLICE_MACHINE_USER_AGENT.js";
@@ -25,35 +24,17 @@ import "node:fs";
25
24
  import "node:path";
26
25
  import './../../_node_modules/node-domexception/index.js';
27
26
  import Blob from './../../_node_modules/fetch-blob/index.js';
28
- const SLICE_SIMULATOR_WAIT_FOR_SELECTOR = "#__iframe-ready";
29
- const SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT = 1e4;
30
- const SLICE_SIMULATOR_SCREENSHOT_SELECTOR = "#__iframe-renderer";
31
- const DEFAULT_SCREENSHOT_VIEWPORT = {
32
- width: 1200,
33
- height: 800
34
- };
35
27
  function assertS3ACLInitialized(s3ACL) {
36
28
  if (s3ACL == void 0) {
37
29
  throw new Error("An S3 ACL has not been initialized. Run `SliceMachineManager.screenshots.prototype.initS3ACL()` before re-calling this method.");
38
30
  }
39
31
  }
40
- function assertBrowserContextInitialized(browserContext) {
41
- if (browserContext == void 0) {
42
- throw new Error("A browser context has not been initialized. Run `SliceMachineManager.screenshots.prototype.initBrowserContext()` before re-calling this method.");
43
- }
44
- }
45
32
  const uploadScreenshotLimit = pLimit(10);
46
- const encodeSliceSimulatorURLPart = (urlPart) => {
47
- return urlPart.replace(/\//g, "--");
48
- };
49
33
  class ScreenshotsManager extends BaseManager {
50
34
  constructor() {
51
35
  super(...arguments);
52
- __publicField(this, "_browserContext");
53
36
  __publicField(this, "_s3ACL");
54
37
  }
55
- async initBrowserContext() {
56
- }
57
38
  async initS3ACL() {
58
39
  const awsACLURL = new URL("create", API_ENDPOINTS.AwsAclProvider);
59
40
  const awsACLRes = await this._fetch({ url: awsACLURL });
@@ -97,53 +78,6 @@ class ScreenshotsManager extends BaseManager {
97
78
  imgixEndpoint: awsACL.imgixEndpoint
98
79
  };
99
80
  }
100
- // TODO: Abstract to a generic `captureScreenshot()` method that is
101
- // used within a Slice-specific method in SliceManager.
102
- async captureSliceSimulatorScreenshot(args) {
103
- assertBrowserContextInitialized(this._browserContext);
104
- const sliceMachineConfig = await this.project.getSliceMachineConfig();
105
- if (!sliceMachineConfig.localSliceSimulatorURL) {
106
- throw new Error("A local Slice Simulator URL must be configured in your Slice Machine configuration file.");
107
- }
108
- const { model } = await this.slices.readSlice({
109
- libraryID: args.libraryID,
110
- sliceID: args.sliceID
111
- });
112
- if (!model) {
113
- throw new Error(`Did not find a Slice in library "${args.libraryID}" with ID "${args.sliceID}".`);
114
- }
115
- const viewport = args.viewport || DEFAULT_SCREENSHOT_VIEWPORT;
116
- const url = new URL(`./${encodeSliceSimulatorURLPart(args.libraryID)}/${model.name}/${args.variationID}/screenshot`, args.sliceMachineUIOrigin);
117
- url.searchParams.set("screenWidth", viewport.width.toString());
118
- url.searchParams.set("screenHeight", viewport.height.toString());
119
- const isURLAccessible = await checkIsURLAccessible(url.toString());
120
- if (!isURLAccessible) {
121
- throw new Error(`Slice Simulator screenshot URL is not accessible: ${url}`);
122
- }
123
- const page = await this._browserContext.newPage();
124
- page.setViewport(viewport);
125
- await page.goto(url.toString(), { waitUntil: ["load", "networkidle0"] });
126
- await page.waitForSelector(SLICE_SIMULATOR_WAIT_FOR_SELECTOR, {
127
- timeout: SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT
128
- });
129
- const element = await page.$(SLICE_SIMULATOR_SCREENSHOT_SELECTOR);
130
- if (!element) {
131
- const baseURL = new URL(url.pathname, url.origin);
132
- throw new Error(`Slice Simulator did not find ${SLICE_SIMULATOR_WAIT_FOR_SELECTOR} on the page. Verify the URL is correct: ${baseURL}`);
133
- }
134
- const data = await element.screenshot({
135
- encoding: "binary",
136
- clip: {
137
- width: viewport.width,
138
- height: viewport.height,
139
- x: 0,
140
- y: 0
141
- }
142
- });
143
- return {
144
- data
145
- };
146
- }
147
81
  async uploadScreenshot(args) {
148
82
  assertS3ACLInitialized(this._s3ACL);
149
83
  const formData = new FormData();
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenshotsManager.js","sources":["../../../../src/managers/screenshots/ScreenshotsManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport pLimit from \"p-limit\";\nimport fetch, { FormData, Blob, Response } from \"../../lib/fetch\";\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\";\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\n// TODO(DT-1534): Use Puppeteer types if we want reactive Puppeteer screenshots\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Viewport = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype BrowserContext = any;\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\nconst uploadScreenshotLimit = pLimit(10);\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\t// TODO(DT-1534): Uncomment to enable Puppeteer screenshots or delete if we decide to remove Puppeteer\n\t\t//\n\t\t// if (this._browserContext) {\n\t\t// \treturn;\n\t\t// }\n\t\t//\n\t\t// let puppeteer: typeof import(\"puppeteer\");\n\t\t// try {\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\t\t// try {\n\t\t// \tconst browser = await puppeteer.launch({ headless: \"new\" });\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\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\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\t\tcause: error,\n\t\t\t});\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\t\tcause: error,\n\t\t\t});\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 s3ACLEndpoint = this._s3ACL.uploadEndpoint;\n\t\tconst res = await uploadScreenshotLimit(() =>\n\t\t\tfetch(s3ACLEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t}),\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\tconst text = await res.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to upload screenshot with status code: ${res.status}`,\n\t\t\t\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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\tconst text = await res.text();\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\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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":["error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,oCAAoC;AAC1C,MAAM,4CAA4C;AAClD,MAAM,sCAAsC;AAQ5C,MAAM,8BAAwC;AAAA,EAC7C,OAAO;AAAA,EACP,QAAQ;;AAGT,SAAS,uB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KAAK,KAAK,OAAO,aAAa;AAC9C,UAAA,aAAa,IAAI,QAAQ,iBAAiB;AAEvC,aAAA;AAAA,QACN,KAAK,IAAI,SAAU;AAAA,MAAA;AAAA,WAEd;AACA,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,iDAAiD,IAAI,UACrD;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;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,iBAAiB,cAAc,cAAc;AAAA,IAAA,CAC1D;AACG,QAAA,CAAC,IAAI,IAAI;AACN,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,wDAAwD,IAAI,UAC5D;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,MAAM,OAAO,MAIpB;AACA,UAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAClE,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAE5D,WAAA,MAAM,MAAM,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,cAAc;AAAA,QACd,GAAI,KAAK,OAAO,EAAE,gBAAgB,uBAAuB;MACzD;AAAA,MACD,QAAQ,KAAK;AAAA,IAAA,CACb;AAAA,EACF;AACA;"}
1
+ {"version":3,"file":"ScreenshotsManager.js","sources":["../../../../src/managers/screenshots/ScreenshotsManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport pLimit from \"p-limit\";\nimport fetch, { FormData, Blob, Response } from \"../../lib/fetch\";\n\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\";\n\nimport { BaseManager } from \"../BaseManager\";\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\nconst uploadScreenshotLimit = pLimit(10);\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 _s3ACL: S3ACL | undefined;\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\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\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\t\tcause: error,\n\t\t\t});\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\t\tcause: error,\n\t\t\t});\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\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 s3ACLEndpoint = this._s3ACL.uploadEndpoint;\n\t\tconst res = await uploadScreenshotLimit(() =>\n\t\t\tfetch(s3ACLEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: formData,\n\t\t\t}),\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\tconst text = await res.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Unable to upload screenshot with status code: ${res.status}`,\n\t\t\t\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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\tconst text = await res.text();\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\t{\n\t\t\t\t\tcause: text,\n\t\t\t\t},\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":["error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,uBACR,OAAwB;AAExB,MAAI,SAAS,QAAW;AACjB,UAAA,IAAI,MACT,gIAAgI;AAAA,EAEjI;AACF;AAEA,MAAM,wBAAwB,OAAO,EAAE;AAejC,MAAO,2BAA2B,YAAW;AAAA,EAA7C;AAAA;AACG;AAAA;AAAA,EAER,MAAM,YAAS;AAMd,UAAM,YAAY,IAAI,IAAI,UAAU,cAAc,cAAc;AAChE,UAAM,YAAY,MAAM,KAAK,OAAO,EAAE,KAAK,WAAW;AAEhD,UAAA,aAAa,MAAM,UAAU;AAC/B,QAAA;AACA,QAAA;AACU,mBAAA,KAAK,MAAM,UAAU;AAAA,aAC1BA;AAER,YAAM,IAAI,MACT,iCAAiC,cAAc,cAC/C;AAAA,QACC,OAAOA;AAAAA,MAAA,CACP;AAAA,IAEF;AAED,UAAM,EAAE,OAAO,QAAQ,MAAU,IAAA,OAChC,EAAE,aAAa;AAAA,MACd,EAAE,KAAK;AAAA,QACN,QAAQ,EAAE,KAAK;AAAA,UACd,KAAK,EAAE;AAAA,UACP,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;AAAA,QAAA,CACnC;AAAA,QACD,eAAe,EAAE;AAAA,MAAA,CACjB;AAAA,MACD,EAAE,QAAQ;AAAA,QACT,SAAS,EAAE;AAAA,QACX,SAAS,EAAE;AAAA,QACX,OAAO,EAAE;AAAA,MAAA,CACT;AAAA,IAAA,CACD,GACD,UAAU;AAGX,QAAI,OAAO;A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,QACN,KAAK,IAAI,SAAU;AAAA,MAAA;AAAA,WAEd;AACA,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,iDAAiD,IAAI,UACrD;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;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,iBAAiB,cAAc,cAAc;AAAA,IAAA,CAC1D;AACG,QAAA,CAAC,IAAI,IAAI;AACN,YAAA,OAAO,MAAM,IAAI;AACvB,YAAM,IAAI,MACT,wDAAwD,IAAI,UAC5D;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,MAAM,OAAO,MAIpB;AACA,UAAM,sBAAsB,MAAM,KAAK,KAAK,uBAAsB;AAClE,UAAM,qBAAqB,MAAM,KAAK,QAAQ,sBAAqB;AAE5D,WAAA,MAAM,MAAM,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,cAAc;AAAA,QACd,GAAI,KAAK,OAAO,EAAE,gBAAgB,uBAAuB;MACzD;AAAA,MACD,QAAQ,KAAK;AAAA,IAAA,CACb;AAAA,EACF;AACA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\tusers_invite_button_clicked: \"users-invite-button-clicked\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_openAddFromTemplates: \"custom-type:open-add-from-templates\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tlegacySlice_converted: \"legacy-slice:converted\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.users_invite_button_clicked]:\n\t\t\"Slice Machine Users Invite Button Clicked\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_openAddFromTemplates]:\n\t\t\"SliceMachine Open Add from templates\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.legacySlice_converted]:\n\t\t\"SliceMachine Legacy Slice Converted\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{\n\t\trating: number;\n\t\tcomment: string;\n\t\ttype: \"onboarding\" | \"advanced repository\";\n\t}\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype UsersInviteButtonClickedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.users_invite_button_clicked\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t\torigin: \"onboarding\" | \"table\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeOpenAddFromTemplatesEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_openAddFromTemplates,\n\t{ customTypeId: string; customTypeFormat: CustomTypeFormat }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string; sliceTemplate?: string }\n>;\n\ntype LegacySliceConvertedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.legacySlice_converted,\n\t{\n\t\tid: string;\n\t\tvariation: string;\n\t\tlibrary: string;\n\t\tconversionType:\n\t\t\t| \"as_new_slice\"\n\t\t\t| \"as_new_variation\"\n\t\t\t| \"merge_with_identical\";\n\t}\n>;\n\ntype ScreenshotTakenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.screenshotTaken,\n\t{\n\t\ttype: \"custom\" | \"automatic\";\n\t\tmethod: \"fromSimulator\" | \"upload\" | \"dragAndDrop\";\n\t}\n>;\n\ntype ChangesPushedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_pushed,\n\t{\n\t\tcustomTypesCreated: number;\n\t\tcustomTypesModified: number;\n\t\tcustomTypesDeleted: number;\n\t\tslicesCreated: number;\n\t\tslicesModified: number;\n\t\tslicesDeleted: number;\n\t\tmissingScreenshots: number;\n\t\ttotal: number;\n\t\tduration: number;\n\t\thasDeletedDocuments: boolean;\n\t}\n>;\n\ntype ChangesLimitReachSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_limitReach,\n\t{ limitType: LimitType }\n>;\n\ntype EditorWidgetUsedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.editor_widgetUsed,\n\t{ sliceId: string }\n>;\n\nexport type SegmentEvents =\n\t| CommandInitStartSegmentEvent\n\t| CommandInitIdentifySegmentEvent\n\t| CommandInitEndSegmentEvent\n\t| ReviewSegmentEvent\n\t| SliceSimulatorSetupSegmentEvent\n\t| SliceSimulatorOpenSegmentEvent\n\t| SliceSimulatorIsNotRunningSegmentEvent\n\t| PageViewSegmentEvent\n\t| OpenVideoTutorialsSegmentEvent\n\t| CustomTypeCreatedSegmentEvent\n\t| CustomTypeFieldAddedSegmentEvent\n\t| CustomTypeSliceZoneUpdatedSegmentEvent\n\t| CustomTypeOpenAddFromTemplatesEvent\n\t| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| LegacySliceConvertedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent\n\t| OpenPageSnippetSegmentEvent\n\t| CopyPageSnippetSegmentEvent\n\t| UsersInviteButtonClickedSegmentEvent;\n"],"names":[],"mappings":";;AAGO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,6BAA6B;AAAA,EAC7B,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,iCAAiC;AAAA,EACjC,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;;AAKb,MAAM,wBAAwB;AAAA,EACpC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GAAG;AAAA,EAC1C,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,MAAM,GAAG;AAAA,EAC3B,CAAC,iBAAiB,oBAAoB,GAAG;AAAA,EACzC,CAAC,iBAAiB,mBAAmB,GAAG;AAAA,EACxC,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,+BAA+B,GAChD;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;AAAA,EACtC,CAAC,iBAAiB,iBAAiB,GAClC;AAAA,EACD,CAAC,iBAAiB,iBAAiB,GAClC;;;;"}
1
+ {"version":3,"file":"types.cjs","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\tusers_invite_button_clicked: \"users-invite-button-clicked\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_openAddFromTemplates: \"custom-type:open-add-from-templates\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tlegacySlice_converted: \"legacy-slice:converted\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.users_invite_button_clicked]:\n\t\t\"Slice Machine Users Invite Button Clicked\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_openAddFromTemplates]:\n\t\t\"SliceMachine Open Add from templates\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.legacySlice_converted]:\n\t\t\"SliceMachine Legacy Slice Converted\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{\n\t\trating: number;\n\t\tcomment: string;\n\t\ttype: \"onboarding\" | \"advanced repository\";\n\t}\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype UsersInviteButtonClickedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.users_invite_button_clicked\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t\torigin: \"onboarding\" | \"table\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeOpenAddFromTemplatesEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_openAddFromTemplates,\n\t{ customTypeId: string; customTypeFormat: CustomTypeFormat }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string; sliceTemplate?: string }\n>;\n\ntype LegacySliceConvertedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.legacySlice_converted,\n\t{\n\t\tid: string;\n\t\tvariation: string;\n\t\tlibrary: string;\n\t\tconversionType:\n\t\t\t| \"as_new_slice\"\n\t\t\t| \"as_new_variation\"\n\t\t\t| \"merge_with_identical\";\n\t}\n>;\n\ntype ScreenshotTakenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.screenshotTaken,\n\t{\n\t\ttype: \"custom\";\n\t\tmethod: \"upload\" | \"dragAndDrop\";\n\t}\n>;\n\ntype ChangesPushedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_pushed,\n\t{\n\t\tcustomTypesCreated: number;\n\t\tcustomTypesModified: number;\n\t\tcustomTypesDeleted: number;\n\t\tslicesCreated: number;\n\t\tslicesModified: number;\n\t\tslicesDeleted: number;\n\t\tmissingScreenshots: number;\n\t\ttotal: number;\n\t\tduration: number;\n\t\thasDeletedDocuments: boolean;\n\t}\n>;\n\ntype ChangesLimitReachSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_limitReach,\n\t{ limitType: LimitType }\n>;\n\ntype EditorWidgetUsedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.editor_widgetUsed,\n\t{ sliceId: string }\n>;\n\nexport type SegmentEvents =\n\t| CommandInitStartSegmentEvent\n\t| CommandInitIdentifySegmentEvent\n\t| CommandInitEndSegmentEvent\n\t| ReviewSegmentEvent\n\t| SliceSimulatorSetupSegmentEvent\n\t| SliceSimulatorOpenSegmentEvent\n\t| SliceSimulatorIsNotRunningSegmentEvent\n\t| PageViewSegmentEvent\n\t| OpenVideoTutorialsSegmentEvent\n\t| CustomTypeCreatedSegmentEvent\n\t| CustomTypeFieldAddedSegmentEvent\n\t| CustomTypeSliceZoneUpdatedSegmentEvent\n\t| CustomTypeOpenAddFromTemplatesEvent\n\t| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| LegacySliceConvertedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent\n\t| OpenPageSnippetSegmentEvent\n\t| CopyPageSnippetSegmentEvent\n\t| UsersInviteButtonClickedSegmentEvent;\n"],"names":[],"mappings":";;AAGO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,6BAA6B;AAAA,EAC7B,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,iCAAiC;AAAA,EACjC,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;;AAKb,MAAM,wBAAwB;AAAA,EACpC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GAAG;AAAA,EAC1C,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,MAAM,GAAG;AAAA,EAC3B,CAAC,iBAAiB,oBAAoB,GAAG;AAAA,EACzC,CAAC,iBAAiB,mBAAmB,GAAG;AAAA,EACxC,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,+BAA+B,GAChD;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;AAAA,EACtC,CAAC,iBAAiB,iBAAiB,GAClC;AAAA,EACD,CAAC,iBAAiB,iBAAiB,GAClC;;;;"}
@@ -131,8 +131,8 @@ type LegacySliceConvertedSegmentEvent = SegmentEvent<typeof SegmentEventType.leg
131
131
  conversionType: "as_new_slice" | "as_new_variation" | "merge_with_identical";
132
132
  }>;
133
133
  type ScreenshotTakenSegmentEvent = SegmentEvent<typeof SegmentEventType.screenshotTaken, {
134
- type: "custom" | "automatic";
135
- method: "fromSimulator" | "upload" | "dragAndDrop";
134
+ type: "custom";
135
+ method: "upload" | "dragAndDrop";
136
136
  }>;
137
137
  type ChangesPushedSegmentEvent = SegmentEvent<typeof SegmentEventType.changes_pushed, {
138
138
  customTypesCreated: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\tusers_invite_button_clicked: \"users-invite-button-clicked\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_openAddFromTemplates: \"custom-type:open-add-from-templates\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tlegacySlice_converted: \"legacy-slice:converted\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.users_invite_button_clicked]:\n\t\t\"Slice Machine Users Invite Button Clicked\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_openAddFromTemplates]:\n\t\t\"SliceMachine Open Add from templates\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.legacySlice_converted]:\n\t\t\"SliceMachine Legacy Slice Converted\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{\n\t\trating: number;\n\t\tcomment: string;\n\t\ttype: \"onboarding\" | \"advanced repository\";\n\t}\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype UsersInviteButtonClickedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.users_invite_button_clicked\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t\torigin: \"onboarding\" | \"table\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeOpenAddFromTemplatesEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_openAddFromTemplates,\n\t{ customTypeId: string; customTypeFormat: CustomTypeFormat }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string; sliceTemplate?: string }\n>;\n\ntype LegacySliceConvertedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.legacySlice_converted,\n\t{\n\t\tid: string;\n\t\tvariation: string;\n\t\tlibrary: string;\n\t\tconversionType:\n\t\t\t| \"as_new_slice\"\n\t\t\t| \"as_new_variation\"\n\t\t\t| \"merge_with_identical\";\n\t}\n>;\n\ntype ScreenshotTakenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.screenshotTaken,\n\t{\n\t\ttype: \"custom\" | \"automatic\";\n\t\tmethod: \"fromSimulator\" | \"upload\" | \"dragAndDrop\";\n\t}\n>;\n\ntype ChangesPushedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_pushed,\n\t{\n\t\tcustomTypesCreated: number;\n\t\tcustomTypesModified: number;\n\t\tcustomTypesDeleted: number;\n\t\tslicesCreated: number;\n\t\tslicesModified: number;\n\t\tslicesDeleted: number;\n\t\tmissingScreenshots: number;\n\t\ttotal: number;\n\t\tduration: number;\n\t\thasDeletedDocuments: boolean;\n\t}\n>;\n\ntype ChangesLimitReachSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_limitReach,\n\t{ limitType: LimitType }\n>;\n\ntype EditorWidgetUsedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.editor_widgetUsed,\n\t{ sliceId: string }\n>;\n\nexport type SegmentEvents =\n\t| CommandInitStartSegmentEvent\n\t| CommandInitIdentifySegmentEvent\n\t| CommandInitEndSegmentEvent\n\t| ReviewSegmentEvent\n\t| SliceSimulatorSetupSegmentEvent\n\t| SliceSimulatorOpenSegmentEvent\n\t| SliceSimulatorIsNotRunningSegmentEvent\n\t| PageViewSegmentEvent\n\t| OpenVideoTutorialsSegmentEvent\n\t| CustomTypeCreatedSegmentEvent\n\t| CustomTypeFieldAddedSegmentEvent\n\t| CustomTypeSliceZoneUpdatedSegmentEvent\n\t| CustomTypeOpenAddFromTemplatesEvent\n\t| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| LegacySliceConvertedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent\n\t| OpenPageSnippetSegmentEvent\n\t| CopyPageSnippetSegmentEvent\n\t| UsersInviteButtonClickedSegmentEvent;\n"],"names":[],"mappings":"AAGO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,6BAA6B;AAAA,EAC7B,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,iCAAiC;AAAA,EACjC,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;;AAKb,MAAM,wBAAwB;AAAA,EACpC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GAAG;AAAA,EAC1C,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,MAAM,GAAG;AAAA,EAC3B,CAAC,iBAAiB,oBAAoB,GAAG;AAAA,EACzC,CAAC,iBAAiB,mBAAmB,GAAG;AAAA,EACxC,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,+BAA+B,GAChD;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;AAAA,EACtC,CAAC,iBAAiB,iBAAiB,GAClC;AAAA,EACD,CAAC,iBAAiB,iBAAiB,GAClC;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import { CustomTypeFormat } from \"../customTypes/types\";\nimport type { LimitType } from \"../prismicRepository/types\";\n\nexport const SegmentEventType = {\n\tcommand_init_start: \"command:init:start\",\n\tcommand_init_identify: \"command:init:identify\",\n\tcommand_init_end: \"command:init:end\",\n\treview: \"review\",\n\tsliceSimulator_setup: \"slice-simulator:setup\",\n\tsliceSimulator_open: \"slice-simulator:open\",\n\tsliceSimulator_isNotRunning: \"slice-simulator:is-not-running\",\n\tpageView: \"page-view\",\n\tusers_invite_button_clicked: \"users-invite-button-clicked\",\n\topenVideoTutorials: \"open-video-tutorials\",\n\tcustomType_created: \"custom-type:created\",\n\tcustomType_fieldAdded: \"custom-type:field-added\",\n\tcustomType_sliceZoneUpdated: \"custom-type:slice-zone-updated\",\n\tcustomType_openAddFromTemplates: \"custom-type:open-add-from-templates\",\n\tcustomType_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tlegacySlice_converted: \"legacy-slice:converted\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\n\topen_page_snippet: \"page-type:open-snippet\",\n\tcopy_page_snippet: \"page-type:copy-snippet\",\n} as const;\ntype SegmentEventTypes =\n\t(typeof SegmentEventType)[keyof typeof SegmentEventType];\n\nexport const HumanSegmentEventType = {\n\t[SegmentEventType.command_init_start]: \"SliceMachine Init Start\",\n\t[SegmentEventType.command_init_identify]: \"SliceMachine Init Identify\",\n\t[SegmentEventType.command_init_end]: \"SliceMachine Init End\",\n\t[SegmentEventType.review]: \"SliceMachine Review\",\n\t[SegmentEventType.sliceSimulator_setup]: \"SliceMachine Slice Simulator Setup\",\n\t[SegmentEventType.sliceSimulator_open]: \"SliceMachine Slice Simulator Open\",\n\t[SegmentEventType.sliceSimulator_isNotRunning]:\n\t\t\"SliceMachine Slice Simulator is not running\",\n\t[SegmentEventType.pageView]: \"SliceMachine Page View\",\n\t[SegmentEventType.users_invite_button_clicked]:\n\t\t\"Slice Machine Users Invite Button Clicked\",\n\t[SegmentEventType.openVideoTutorials]: \"SliceMachine Open Video Tutorials\",\n\t[SegmentEventType.customType_created]: \"SliceMachine Custom Type Created\",\n\t[SegmentEventType.customType_fieldAdded]:\n\t\t\"SliceMachine Custom Type Field Added\",\n\t[SegmentEventType.customType_sliceZoneUpdated]:\n\t\t\"SliceMachine Slicezone Updated\",\n\t[SegmentEventType.customType_openAddFromTemplates]:\n\t\t\"SliceMachine Open Add from templates\",\n\t[SegmentEventType.customType_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.legacySlice_converted]:\n\t\t\"SliceMachine Legacy Slice Converted\",\n\t[SegmentEventType.screenshotTaken]: \"SliceMachine Screenshot Taken\",\n\t[SegmentEventType.changes_pushed]: \"SliceMachine Changes Pushed\",\n\t[SegmentEventType.changes_limitReach]: \"SliceMachine Changes Limit Reach\",\n\t[SegmentEventType.editor_widgetUsed]: \"SliceMachine Editor Widget Used\",\n\t[SegmentEventType.open_page_snippet]:\n\t\t\"SliceMachine Opens Page Type Snippet Dialog\",\n\t[SegmentEventType.copy_page_snippet]:\n\t\t\"Slice Machine page code snippet copied\",\n} as const;\nexport type HumanSegmentEventTypes =\n\t(typeof HumanSegmentEventType)[keyof typeof HumanSegmentEventType];\n\ntype SegmentEvent<\n\tTType extends SegmentEventTypes,\n\tTProperties extends Record<string, unknown> | void = void,\n> = TProperties extends void\n\t? {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t }\n\t: {\n\t\t\tevent: TType;\n\t\t\trepository?: string;\n\t } & TProperties;\n\ntype CommandInitStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_start\n>;\n\n// This event feels off, we have a dedicated `identify` method...\ntype CommandInitIdentifySegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_identify\n>;\n\ntype CommandInitEndSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.command_init_end,\n\t{ framework: string; success: boolean; error?: string }\n>;\n\ntype ReviewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.review,\n\t{\n\t\trating: number;\n\t\tcomment: string;\n\t\ttype: \"onboarding\" | \"advanced repository\";\n\t}\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning\n>;\n\ntype PageViewSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.pageView,\n\t{\n\t\turl: string;\n\t\tpath: string;\n\t\tsearch: string;\n\t\ttitle: string;\n\t\treferrer: string;\n\t\tadapter: string;\n\t}\n>;\n\ntype OpenPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.open_page_snippet,\n\t{ framework: string }\n>;\n\ntype CopyPageSnippetSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.copy_page_snippet,\n\t{ framework: string }\n>;\n\ntype UsersInviteButtonClickedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.users_invite_button_clicked\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t\torigin: \"onboarding\" | \"table\";\n\t}\n>;\n\ntype CustomTypeFieldAddedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_fieldAdded,\n\t{\n\t\tid: string; // field id\n\t\tname: string; // custom type id\n\t\tzone: \"static\" | \"repeatable\";\n\t\ttype: string;\n\t}\n>;\n\ntype CustomTypeSliceZoneUpdatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_sliceZoneUpdated,\n\t{ customTypeId: string }\n>;\n\ntype CustomTypeOpenAddFromTemplatesEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_openAddFromTemplates,\n\t{ customTypeId: string; customTypeFormat: CustomTypeFormat }\n>;\n\ntype CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{\n\t\tid: string;\n\t\tname: string;\n\t\tformat: CustomTypeFormat;\n\t\ttype: \"repeatable\" | \"single\";\n\t}\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string; sliceTemplate?: string }\n>;\n\ntype LegacySliceConvertedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.legacySlice_converted,\n\t{\n\t\tid: string;\n\t\tvariation: string;\n\t\tlibrary: string;\n\t\tconversionType:\n\t\t\t| \"as_new_slice\"\n\t\t\t| \"as_new_variation\"\n\t\t\t| \"merge_with_identical\";\n\t}\n>;\n\ntype ScreenshotTakenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.screenshotTaken,\n\t{\n\t\ttype: \"custom\";\n\t\tmethod: \"upload\" | \"dragAndDrop\";\n\t}\n>;\n\ntype ChangesPushedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_pushed,\n\t{\n\t\tcustomTypesCreated: number;\n\t\tcustomTypesModified: number;\n\t\tcustomTypesDeleted: number;\n\t\tslicesCreated: number;\n\t\tslicesModified: number;\n\t\tslicesDeleted: number;\n\t\tmissingScreenshots: number;\n\t\ttotal: number;\n\t\tduration: number;\n\t\thasDeletedDocuments: boolean;\n\t}\n>;\n\ntype ChangesLimitReachSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.changes_limitReach,\n\t{ limitType: LimitType }\n>;\n\ntype EditorWidgetUsedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.editor_widgetUsed,\n\t{ sliceId: string }\n>;\n\nexport type SegmentEvents =\n\t| CommandInitStartSegmentEvent\n\t| CommandInitIdentifySegmentEvent\n\t| CommandInitEndSegmentEvent\n\t| ReviewSegmentEvent\n\t| SliceSimulatorSetupSegmentEvent\n\t| SliceSimulatorOpenSegmentEvent\n\t| SliceSimulatorIsNotRunningSegmentEvent\n\t| PageViewSegmentEvent\n\t| OpenVideoTutorialsSegmentEvent\n\t| CustomTypeCreatedSegmentEvent\n\t| CustomTypeFieldAddedSegmentEvent\n\t| CustomTypeSliceZoneUpdatedSegmentEvent\n\t| CustomTypeOpenAddFromTemplatesEvent\n\t| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| LegacySliceConvertedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent\n\t| OpenPageSnippetSegmentEvent\n\t| CopyPageSnippetSegmentEvent\n\t| UsersInviteButtonClickedSegmentEvent;\n"],"names":[],"mappings":"AAGO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,6BAA6B;AAAA,EAC7B,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,iCAAiC;AAAA,EACjC,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;;AAKb,MAAM,wBAAwB;AAAA,EACpC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GAAG;AAAA,EAC1C,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,MAAM,GAAG;AAAA,EAC3B,CAAC,iBAAiB,oBAAoB,GAAG;AAAA,EACzC,CAAC,iBAAiB,mBAAmB,GAAG;AAAA,EACxC,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,+BAA+B,GAChD;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;AAAA,EACtC,CAAC,iBAAiB,iBAAiB,GAClC;AAAA,EACD,CAAC,iBAAiB,iBAAiB,GAClC;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/manager",
3
- "version": "0.15.3-dev-next-release.2",
3
+ "version": "0.15.3-dev-next-release.3",
4
4
  "description": "Manage all aspects of a Slice Machine project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,7 +68,7 @@
68
68
  "@prismicio/custom-types-client": "^1.2.0-alpha.0",
69
69
  "@prismicio/mocks": "^2.0.0-alpha.2",
70
70
  "@prismicio/types-internal": "^2.2.0",
71
- "@slicemachine/plugin-kit": "^0.4.24-dev-next-release.2",
71
+ "@slicemachine/plugin-kit": "^0.4.24-dev-next-release.3",
72
72
  "@wooorm/starry-night": "^1.6.0",
73
73
  "analytics-node": "^6.2.0",
74
74
  "cookie": "^0.5.0",
@@ -134,5 +134,5 @@
134
134
  "engines": {
135
135
  "node": ">=14.15.0"
136
136
  },
137
- "gitHead": "332d488ecf32ef67995b101972e196465f8b6dab"
137
+ "gitHead": "914d307013e373656db515d9c677fdb8c2c35a2c"
138
138
  }
@@ -40,7 +40,6 @@ const omitProcedures = defineOmits<SliceMachineManager>()([
40
40
  "sliceTemplateLibrary._sliceMachineManager",
41
41
  "getSliceMachinePluginRunner",
42
42
  "getPrismicAuthManager",
43
- "screenshots.browserContext",
44
43
  ]);
45
44
 
46
45
  export type SliceMachineManagerMiddleware = RPCMiddleware<
@@ -3,7 +3,6 @@ import { fileTypeFromBuffer } from "file-type";
3
3
  import pLimit from "p-limit";
4
4
  import fetch, { FormData, Blob, Response } from "../../lib/fetch";
5
5
 
6
- import { checkIsURLAccessible } from "../../lib/checkIsURLAccessible";
7
6
  import { createContentDigest } from "../../lib/createContentDigest";
8
7
  import { decode } from "../../lib/decode";
9
8
 
@@ -13,21 +12,6 @@ import { API_ENDPOINTS } from "../../constants/API_ENDPOINTS";
13
12
 
14
13
  import { BaseManager } from "../BaseManager";
15
14
 
16
- const SLICE_SIMULATOR_WAIT_FOR_SELECTOR = "#__iframe-ready";
17
- const SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT = 10_000; // ms
18
- const SLICE_SIMULATOR_SCREENSHOT_SELECTOR = "#__iframe-renderer";
19
-
20
- // TODO(DT-1534): Use Puppeteer types if we want reactive Puppeteer screenshots
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- type Viewport = any;
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- type BrowserContext = any;
25
-
26
- const DEFAULT_SCREENSHOT_VIEWPORT: Viewport = {
27
- width: 1200,
28
- height: 800,
29
- };
30
-
31
15
  function assertS3ACLInitialized(
32
16
  s3ACL: S3ACL | undefined,
33
17
  ): asserts s3ACL is NonNullable<typeof s3ACL> {
@@ -38,48 +22,8 @@ function assertS3ACLInitialized(
38
22
  }
39
23
  }
40
24
 
41
- function assertBrowserContextInitialized(
42
- browserContext: BrowserContext | undefined,
43
- ): asserts browserContext is NonNullable<typeof browserContext> {
44
- if (browserContext == undefined) {
45
- throw new Error(
46
- "A browser context has not been initialized. Run `SliceMachineManager.screenshots.prototype.initBrowserContext()` before re-calling this method.",
47
- );
48
- }
49
- }
50
-
51
25
  const uploadScreenshotLimit = pLimit(10);
52
26
 
53
- /**
54
- * Encodes a part of a Slice Simulator URL to ensure it can be added to a URL
55
- * safely.
56
- *
57
- * The encoding logic must match Slice Machine UI's URL encoding practices.
58
- * Today, that requires the following:
59
- *
60
- * - Replace "/" with "--" (e.g. a Slice Library ID of "./slices" should turn into
61
- * ".--slices")
62
- *
63
- * @param urlPart - A part of the URL.
64
- *
65
- * @returns `urlPart` encoded for use in a URL.
66
- */
67
- const encodeSliceSimulatorURLPart = (urlPart: string): string => {
68
- return urlPart.replace(/\//g, "--");
69
- };
70
-
71
- type ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs = {
72
- sliceMachineUIOrigin: string;
73
- libraryID: string;
74
- sliceID: string;
75
- variationID: string;
76
- viewport?: Viewport;
77
- };
78
-
79
- type ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType = {
80
- data: Buffer;
81
- };
82
-
83
27
  type ScreenshotsManagerUploadScreenshotArgs = {
84
28
  data: Buffer;
85
29
  keyPrefix?: string;
@@ -94,35 +38,8 @@ type ScreenshotsManagerDeleteScreenshotFolderArgs = {
94
38
  };
95
39
 
96
40
  export class ScreenshotsManager extends BaseManager {
97
- private _browserContext: BrowserContext | undefined;
98
41
  private _s3ACL: S3ACL | undefined;
99
42
 
100
- async initBrowserContext(): Promise<void> {
101
- // TODO(DT-1534): Uncomment to enable Puppeteer screenshots or delete if we decide to remove Puppeteer
102
- //
103
- // if (this._browserContext) {
104
- // return;
105
- // }
106
- //
107
- // let puppeteer: typeof import("puppeteer");
108
- // try {
109
- // // Lazy-load Puppeteer only once it is needed.
110
- // puppeteer = await import("puppeteer");
111
- // } catch {
112
- // throw new InternalError(
113
- // "Screenshots require Puppeteer but Puppeteer was not found. Check that the `puppeteer` package is installed before trying again.",
114
- // );
115
- // }
116
- // try {
117
- // const browser = await puppeteer.launch({ headless: "new" });
118
- // this._browserContext = await browser.createIncognitoBrowserContext();
119
- // } catch (error) {
120
- // throw new InternalError(
121
- // "Error launching browser. If you're using an Apple Silicon Mac, check if Rosetta is installed.",
122
- // );
123
- // }
124
- }
125
-
126
43
  async initS3ACL(): Promise<void> {
127
44
  // TODO: we need to find a way to create a new AWS ACL only when necessary (e.g., when it has expired).
128
45
  // if (this._s3ACL) {
@@ -184,86 +101,6 @@ export class ScreenshotsManager extends BaseManager {
184
101
  };
185
102
  }
186
103
 
187
- // TODO: Abstract to a generic `captureScreenshot()` method that is
188
- // used within a Slice-specific method in SliceManager.
189
- async captureSliceSimulatorScreenshot(
190
- args: ScreenshotsManagerCaptureSliceSimulatorScreenshotArgs,
191
- ): Promise<ScreenshotsManagerCaptureSliceSimulatorScreenshotReturnType> {
192
- assertBrowserContextInitialized(this._browserContext);
193
-
194
- const sliceMachineConfig = await this.project.getSliceMachineConfig();
195
-
196
- if (!sliceMachineConfig.localSliceSimulatorURL) {
197
- // TODO: Provide a more helpful error message.
198
- throw new Error(
199
- "A local Slice Simulator URL must be configured in your Slice Machine configuration file.",
200
- );
201
- }
202
-
203
- const { model } = await this.slices.readSlice({
204
- libraryID: args.libraryID,
205
- sliceID: args.sliceID,
206
- });
207
- if (!model) {
208
- throw new Error(
209
- `Did not find a Slice in library "${args.libraryID}" with ID "${args.sliceID}".`,
210
- );
211
- }
212
-
213
- const viewport = args.viewport || DEFAULT_SCREENSHOT_VIEWPORT;
214
-
215
- // TODO: Change `model.name` to `args.sliceID`?
216
- // Making that change would require changing the screenshot
217
- // page path in Slice Machine UI.
218
- const url = new URL(
219
- `./${encodeSliceSimulatorURLPart(args.libraryID)}/${model.name}/${
220
- args.variationID
221
- }/screenshot`,
222
- args.sliceMachineUIOrigin,
223
- );
224
- url.searchParams.set("screenWidth", viewport.width.toString());
225
- url.searchParams.set("screenHeight", viewport.height.toString());
226
-
227
- const isURLAccessible = await checkIsURLAccessible(url.toString());
228
-
229
- if (!isURLAccessible) {
230
- throw new Error(
231
- `Slice Simulator screenshot URL is not accessible: ${url}`,
232
- );
233
- }
234
-
235
- const page = await this._browserContext.newPage();
236
- page.setViewport(viewport);
237
-
238
- await page.goto(url.toString(), { waitUntil: ["load", "networkidle0"] });
239
- await page.waitForSelector(SLICE_SIMULATOR_WAIT_FOR_SELECTOR, {
240
- timeout: SLICE_SIMULATOR_WAIT_FOR_SELECTOR_TIMEOUT,
241
- });
242
-
243
- const element = await page.$(SLICE_SIMULATOR_SCREENSHOT_SELECTOR);
244
- if (!element) {
245
- const baseURL = new URL(url.pathname, url.origin);
246
-
247
- throw new Error(
248
- `Slice Simulator did not find ${SLICE_SIMULATOR_WAIT_FOR_SELECTOR} on the page. Verify the URL is correct: ${baseURL}`,
249
- );
250
- }
251
-
252
- const data = (await element.screenshot({
253
- encoding: "binary",
254
- clip: {
255
- width: viewport.width,
256
- height: viewport.height,
257
- x: 0,
258
- y: 0,
259
- },
260
- })) as Buffer;
261
-
262
- return {
263
- data,
264
- };
265
- }
266
-
267
104
  async uploadScreenshot(
268
105
  args: ScreenshotsManagerUploadScreenshotArgs,
269
106
  ): Promise<ScreenshotsManagerUploadScreenshotReturnType> {
@@ -206,8 +206,8 @@ type LegacySliceConvertedSegmentEvent = SegmentEvent<
206
206
  type ScreenshotTakenSegmentEvent = SegmentEvent<
207
207
  typeof SegmentEventType.screenshotTaken,
208
208
  {
209
- type: "custom" | "automatic";
210
- method: "fromSimulator" | "upload" | "dragAndDrop";
209
+ type: "custom";
210
+ method: "upload" | "dragAndDrop";
211
211
  }
212
212
  >;
213
213
 
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fetch = require("./fetch.cjs");
4
- const checkIsURLAccessible = async (url) => {
5
- const res = await fetch.default(url);
6
- return res.ok;
7
- };
8
- exports.checkIsURLAccessible = checkIsURLAccessible;
9
- //# sourceMappingURL=checkIsURLAccessible.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkIsURLAccessible.cjs","sources":["../../../src/lib/checkIsURLAccessible.ts"],"sourcesContent":["import fetch from \"./fetch\";\n\nexport const checkIsURLAccessible = async (url: string): Promise<boolean> => {\n\tconst res = await fetch(url);\n\n\treturn res.ok;\n};\n"],"names":["fetch"],"mappings":";;;AAEa,MAAA,uBAAuB,OAAO,QAAiC;AACrE,QAAA,MAAM,MAAMA,cAAM,GAAG;AAE3B,SAAO,IAAI;AACZ;;"}
@@ -1,9 +0,0 @@
1
- import fetch from "./fetch.js";
2
- const checkIsURLAccessible = async (url) => {
3
- const res = await fetch(url);
4
- return res.ok;
5
- };
6
- export {
7
- checkIsURLAccessible
8
- };
9
- //# sourceMappingURL=checkIsURLAccessible.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkIsURLAccessible.js","sources":["../../../src/lib/checkIsURLAccessible.ts"],"sourcesContent":["import fetch from \"./fetch\";\n\nexport const checkIsURLAccessible = async (url: string): Promise<boolean> => {\n\tconst res = await fetch(url);\n\n\treturn res.ok;\n};\n"],"names":[],"mappings":";AAEa,MAAA,uBAAuB,OAAO,QAAiC;AACrE,QAAA,MAAM,MAAM,MAAM,GAAG;AAE3B,SAAO,IAAI;AACZ;"}