@slicemachine/manager 0.1.1-dev-plugins-m1-validation.0 → 0.1.1-dev-plugins-m2-validation.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/auth/createPrismicAuthManagerMiddleware.cjs +2 -1
  2. package/dist/auth/createPrismicAuthManagerMiddleware.cjs.map +1 -1
  3. package/dist/auth/createPrismicAuthManagerMiddleware.js +2 -1
  4. package/dist/auth/createPrismicAuthManagerMiddleware.js.map +1 -1
  5. package/dist/errors.cjs +5 -1
  6. package/dist/errors.cjs.map +1 -1
  7. package/dist/errors.js +5 -1
  8. package/dist/errors.js.map +1 -1
  9. package/dist/managers/SliceMachineManager.cjs +35 -18
  10. package/dist/managers/SliceMachineManager.cjs.map +1 -1
  11. package/dist/managers/SliceMachineManager.d.ts +1 -0
  12. package/dist/managers/SliceMachineManager.js +35 -18
  13. package/dist/managers/SliceMachineManager.js.map +1 -1
  14. package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +22 -21
  15. package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
  16. package/dist/managers/prismicRepository/PrismicRepositoryManager.js +22 -21
  17. package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
  18. package/dist/managers/simulator/SimulatorManager.cjs +5 -0
  19. package/dist/managers/simulator/SimulatorManager.cjs.map +1 -1
  20. package/dist/managers/simulator/SimulatorManager.d.ts +1 -0
  21. package/dist/managers/simulator/SimulatorManager.js +5 -0
  22. package/dist/managers/simulator/SimulatorManager.js.map +1 -1
  23. package/dist/managers/telemetry/TelemetryManager.cjs +3 -3
  24. package/dist/managers/telemetry/TelemetryManager.cjs.map +1 -1
  25. package/dist/managers/telemetry/TelemetryManager.js +3 -3
  26. package/dist/managers/telemetry/TelemetryManager.js.map +1 -1
  27. package/package.json +5 -5
  28. package/src/auth/createPrismicAuthManagerMiddleware.ts +3 -1
  29. package/src/errors.ts +11 -3
  30. package/src/managers/SliceMachineManager.ts +49 -22
  31. package/src/managers/prismicRepository/PrismicRepositoryManager.ts +28 -26
  32. package/src/managers/simulator/SimulatorManager.ts +10 -0
  33. package/src/managers/telemetry/TelemetryManager.ts +3 -3
@@ -43,7 +43,8 @@ const createPrismicAuthManagerMiddleware = (args) => {
43
43
  }));
44
44
  return h3.defineNodeMiddleware(async (req, res) => {
45
45
  const event = h3.createEvent(req, res);
46
- return await router.handler(event);
46
+ await router.handler(event);
47
+ res.end();
47
48
  });
48
49
  };
49
50
  exports.createPrismicAuthManagerMiddleware = createPrismicAuthManagerMiddleware;
@@ -1 +1 @@
1
- {"version":3,"file":"createPrismicAuthManagerMiddleware.cjs","sources":["../../../src/auth/createPrismicAuthManagerMiddleware.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport {\n\tcreateEvent,\n\tcreateRouter,\n\tdefineNodeMiddleware,\n\teventHandler,\n\tNodeMiddleware,\n\treadBody,\n} from \"h3\";\n\nimport { decode } from \"../lib/decode\";\n\nimport { PrismicAuthManager } from \"./PrismicAuthManager\";\n\nconst PrismicAuthResponse = t.type({\n\temail: t.string,\n\tcookies: t.array(t.string),\n});\ntype PrismicAuthResponse = t.TypeOf<typeof PrismicAuthResponse>;\n\nexport type PrismicAuthCheckStatusResponse =\n\t| {\n\t\t\tstatus: \"ok\";\n\t\t\tshortId: string;\n\t\t\tintercomHash: string;\n\t }\n\t| {\n\t\t\tstatus: \"pending\";\n\t };\n\nexport type CreatePrismicAuthManagerMiddlewareArgs = {\n\tprismicAuthManager: PrismicAuthManager;\n\tonLoginCallback?: () => void | Promise<void>;\n};\n\nexport const createPrismicAuthManagerMiddleware = (\n\targs: CreatePrismicAuthManagerMiddlewareArgs,\n): NodeMiddleware => {\n\tconst router = createRouter();\n\n\t// Route called by the remote Prismic login page on successful login.\n\trouter.post(\n\t\t\"/\",\n\t\teventHandler(async (event) => {\n\t\t\tconst body = await readBody(event);\n\t\t\tconst { value, error } = decode(PrismicAuthResponse, body);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(`Invalid auth payload: ${error.errors.join(\", \")}`);\n\t\t\t}\n\n\t\t\tawait args.prismicAuthManager.login({\n\t\t\t\temail: value.email,\n\t\t\t\tcookies: value.cookies,\n\t\t\t});\n\n\t\t\tif (args.onLoginCallback) {\n\t\t\t\tawait args.onLoginCallback();\n\t\t\t}\n\n\t\t\treturn {};\n\t\t}),\n\t);\n\n\treturn defineNodeMiddleware(async (req, res) => {\n\t\tconst event = createEvent(req, res);\n\n\t\treturn await router.handler(event);\n\t});\n};\n"],"names":["t","createRouter","eventHandler","readBody","decode","defineNodeMiddleware","createEvent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,sBAAsBA,aAAE,KAAK;AAAA,EAClC,OAAOA,aAAE;AAAA,EACT,SAASA,aAAE,MAAMA,aAAE,MAAM;AACzB,CAAA;AAkBY,MAAA,qCAAqC,CACjD,SACmB;AACnB,QAAM,SAASC,GAAAA;AAGf,SAAO,KACN,KACAC,GAAa,aAAA,OAAO,UAAS;AACtB,UAAA,OAAO,MAAMC,YAAS,KAAK;AACjC,UAAM,EAAE,OAAO,MAAA,IAAUC,OAAAA,OAAO,qBAAqB,IAAI;AAEzD,QAAI,OAAO;AACV,YAAM,IAAI,MAAM,yBAAyB,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,IAClE;AAEK,UAAA,KAAK,mBAAmB,MAAM;AAAA,MACnC,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,IAAA,CACf;AAED,QAAI,KAAK,iBAAiB;AACzB,YAAM,KAAK;IACX;AAED,WAAO;EACP,CAAA,CAAC;AAGI,SAAAC,GAAA,qBAAqB,OAAO,KAAK,QAAO;AACxC,UAAA,QAAQC,GAAAA,YAAY,KAAK,GAAG;AAE3B,WAAA,MAAM,OAAO,QAAQ,KAAK;AAAA,EAAA,CACjC;AACF;;"}
1
+ {"version":3,"file":"createPrismicAuthManagerMiddleware.cjs","sources":["../../../src/auth/createPrismicAuthManagerMiddleware.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport {\n\tcreateEvent,\n\tcreateRouter,\n\tdefineNodeMiddleware,\n\teventHandler,\n\tNodeMiddleware,\n\treadBody,\n} from \"h3\";\n\nimport { decode } from \"../lib/decode\";\n\nimport { PrismicAuthManager } from \"./PrismicAuthManager\";\n\nconst PrismicAuthResponse = t.type({\n\temail: t.string,\n\tcookies: t.array(t.string),\n});\ntype PrismicAuthResponse = t.TypeOf<typeof PrismicAuthResponse>;\n\nexport type PrismicAuthCheckStatusResponse =\n\t| {\n\t\t\tstatus: \"ok\";\n\t\t\tshortId: string;\n\t\t\tintercomHash: string;\n\t }\n\t| {\n\t\t\tstatus: \"pending\";\n\t };\n\nexport type CreatePrismicAuthManagerMiddlewareArgs = {\n\tprismicAuthManager: PrismicAuthManager;\n\tonLoginCallback?: () => void | Promise<void>;\n};\n\nexport const createPrismicAuthManagerMiddleware = (\n\targs: CreatePrismicAuthManagerMiddlewareArgs,\n): NodeMiddleware => {\n\tconst router = createRouter();\n\n\t// Route called by the remote Prismic login page on successful login.\n\trouter.post(\n\t\t\"/\",\n\t\teventHandler(async (event) => {\n\t\t\tconst body = await readBody(event);\n\t\t\tconst { value, error } = decode(PrismicAuthResponse, body);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(`Invalid auth payload: ${error.errors.join(\", \")}`);\n\t\t\t}\n\n\t\t\tawait args.prismicAuthManager.login({\n\t\t\t\temail: value.email,\n\t\t\t\tcookies: value.cookies,\n\t\t\t});\n\n\t\t\tif (args.onLoginCallback) {\n\t\t\t\tawait args.onLoginCallback();\n\t\t\t}\n\n\t\t\treturn {};\n\t\t}),\n\t);\n\n\treturn defineNodeMiddleware(async (req, res) => {\n\t\tconst event = createEvent(req, res);\n\n\t\tawait router.handler(event);\n\n\t\tres.end();\n\t});\n};\n"],"names":["t","createRouter","eventHandler","readBody","decode","defineNodeMiddleware","createEvent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,sBAAsBA,aAAE,KAAK;AAAA,EAClC,OAAOA,aAAE;AAAA,EACT,SAASA,aAAE,MAAMA,aAAE,MAAM;AACzB,CAAA;AAkBY,MAAA,qCAAqC,CACjD,SACmB;AACnB,QAAM,SAASC,GAAAA;AAGf,SAAO,KACN,KACAC,GAAa,aAAA,OAAO,UAAS;AACtB,UAAA,OAAO,MAAMC,YAAS,KAAK;AACjC,UAAM,EAAE,OAAO,MAAA,IAAUC,OAAAA,OAAO,qBAAqB,IAAI;AAEzD,QAAI,OAAO;AACV,YAAM,IAAI,MAAM,yBAAyB,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,IAClE;AAEK,UAAA,KAAK,mBAAmB,MAAM;AAAA,MACnC,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,IAAA,CACf;AAED,QAAI,KAAK,iBAAiB;AACzB,YAAM,KAAK;IACX;AAED,WAAO;EACP,CAAA,CAAC;AAGI,SAAAC,GAAA,qBAAqB,OAAO,KAAK,QAAO;AACxC,UAAA,QAAQC,GAAAA,YAAY,KAAK,GAAG;AAE5B,UAAA,OAAO,QAAQ,KAAK;AAE1B,QAAI,IAAG;AAAA,EAAA,CACP;AACF;;"}
@@ -24,7 +24,8 @@ const createPrismicAuthManagerMiddleware = (args) => {
24
24
  }));
25
25
  return defineNodeMiddleware(async (req, res) => {
26
26
  const event = createEvent(req, res);
27
- return await router.handler(event);
27
+ await router.handler(event);
28
+ res.end();
28
29
  });
29
30
  };
30
31
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"createPrismicAuthManagerMiddleware.js","sources":["../../../src/auth/createPrismicAuthManagerMiddleware.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport {\n\tcreateEvent,\n\tcreateRouter,\n\tdefineNodeMiddleware,\n\teventHandler,\n\tNodeMiddleware,\n\treadBody,\n} from \"h3\";\n\nimport { decode } from \"../lib/decode\";\n\nimport { PrismicAuthManager } from \"./PrismicAuthManager\";\n\nconst PrismicAuthResponse = t.type({\n\temail: t.string,\n\tcookies: t.array(t.string),\n});\ntype PrismicAuthResponse = t.TypeOf<typeof PrismicAuthResponse>;\n\nexport type PrismicAuthCheckStatusResponse =\n\t| {\n\t\t\tstatus: \"ok\";\n\t\t\tshortId: string;\n\t\t\tintercomHash: string;\n\t }\n\t| {\n\t\t\tstatus: \"pending\";\n\t };\n\nexport type CreatePrismicAuthManagerMiddlewareArgs = {\n\tprismicAuthManager: PrismicAuthManager;\n\tonLoginCallback?: () => void | Promise<void>;\n};\n\nexport const createPrismicAuthManagerMiddleware = (\n\targs: CreatePrismicAuthManagerMiddlewareArgs,\n): NodeMiddleware => {\n\tconst router = createRouter();\n\n\t// Route called by the remote Prismic login page on successful login.\n\trouter.post(\n\t\t\"/\",\n\t\teventHandler(async (event) => {\n\t\t\tconst body = await readBody(event);\n\t\t\tconst { value, error } = decode(PrismicAuthResponse, body);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(`Invalid auth payload: ${error.errors.join(\", \")}`);\n\t\t\t}\n\n\t\t\tawait args.prismicAuthManager.login({\n\t\t\t\temail: value.email,\n\t\t\t\tcookies: value.cookies,\n\t\t\t});\n\n\t\t\tif (args.onLoginCallback) {\n\t\t\t\tawait args.onLoginCallback();\n\t\t\t}\n\n\t\t\treturn {};\n\t\t}),\n\t);\n\n\treturn defineNodeMiddleware(async (req, res) => {\n\t\tconst event = createEvent(req, res);\n\n\t\treturn await router.handler(event);\n\t});\n};\n"],"names":[],"mappings":";;;AAcA,MAAM,sBAAsB,EAAE,KAAK;AAAA,EAClC,OAAO,EAAE;AAAA,EACT,SAAS,EAAE,MAAM,EAAE,MAAM;AACzB,CAAA;AAkBY,MAAA,qCAAqC,CACjD,SACmB;AACnB,QAAM,SAAS;AAGf,SAAO,KACN,KACA,aAAa,OAAO,UAAS;AACtB,UAAA,OAAO,MAAM,SAAS,KAAK;AACjC,UAAM,EAAE,OAAO,MAAA,IAAU,OAAO,qBAAqB,IAAI;AAEzD,QAAI,OAAO;AACV,YAAM,IAAI,MAAM,yBAAyB,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,IAClE;AAEK,UAAA,KAAK,mBAAmB,MAAM;AAAA,MACnC,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,IAAA,CACf;AAED,QAAI,KAAK,iBAAiB;AACzB,YAAM,KAAK;IACX;AAED,WAAO;EACP,CAAA,CAAC;AAGI,SAAA,qBAAqB,OAAO,KAAK,QAAO;AACxC,UAAA,QAAQ,YAAY,KAAK,GAAG;AAE3B,WAAA,MAAM,OAAO,QAAQ,KAAK;AAAA,EAAA,CACjC;AACF;"}
1
+ {"version":3,"file":"createPrismicAuthManagerMiddleware.js","sources":["../../../src/auth/createPrismicAuthManagerMiddleware.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport {\n\tcreateEvent,\n\tcreateRouter,\n\tdefineNodeMiddleware,\n\teventHandler,\n\tNodeMiddleware,\n\treadBody,\n} from \"h3\";\n\nimport { decode } from \"../lib/decode\";\n\nimport { PrismicAuthManager } from \"./PrismicAuthManager\";\n\nconst PrismicAuthResponse = t.type({\n\temail: t.string,\n\tcookies: t.array(t.string),\n});\ntype PrismicAuthResponse = t.TypeOf<typeof PrismicAuthResponse>;\n\nexport type PrismicAuthCheckStatusResponse =\n\t| {\n\t\t\tstatus: \"ok\";\n\t\t\tshortId: string;\n\t\t\tintercomHash: string;\n\t }\n\t| {\n\t\t\tstatus: \"pending\";\n\t };\n\nexport type CreatePrismicAuthManagerMiddlewareArgs = {\n\tprismicAuthManager: PrismicAuthManager;\n\tonLoginCallback?: () => void | Promise<void>;\n};\n\nexport const createPrismicAuthManagerMiddleware = (\n\targs: CreatePrismicAuthManagerMiddlewareArgs,\n): NodeMiddleware => {\n\tconst router = createRouter();\n\n\t// Route called by the remote Prismic login page on successful login.\n\trouter.post(\n\t\t\"/\",\n\t\teventHandler(async (event) => {\n\t\t\tconst body = await readBody(event);\n\t\t\tconst { value, error } = decode(PrismicAuthResponse, body);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new Error(`Invalid auth payload: ${error.errors.join(\", \")}`);\n\t\t\t}\n\n\t\t\tawait args.prismicAuthManager.login({\n\t\t\t\temail: value.email,\n\t\t\t\tcookies: value.cookies,\n\t\t\t});\n\n\t\t\tif (args.onLoginCallback) {\n\t\t\t\tawait args.onLoginCallback();\n\t\t\t}\n\n\t\t\treturn {};\n\t\t}),\n\t);\n\n\treturn defineNodeMiddleware(async (req, res) => {\n\t\tconst event = createEvent(req, res);\n\n\t\tawait router.handler(event);\n\n\t\tres.end();\n\t});\n};\n"],"names":[],"mappings":";;;AAcA,MAAM,sBAAsB,EAAE,KAAK;AAAA,EAClC,OAAO,EAAE;AAAA,EACT,SAAS,EAAE,MAAM,EAAE,MAAM;AACzB,CAAA;AAkBY,MAAA,qCAAqC,CACjD,SACmB;AACnB,QAAM,SAAS;AAGf,SAAO,KACN,KACA,aAAa,OAAO,UAAS;AACtB,UAAA,OAAO,MAAM,SAAS,KAAK;AACjC,UAAM,EAAE,OAAO,MAAA,IAAU,OAAO,qBAAqB,IAAI;AAEzD,QAAI,OAAO;AACV,YAAM,IAAI,MAAM,yBAAyB,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,IAClE;AAEK,UAAA,KAAK,mBAAmB,MAAM;AAAA,MACnC,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,IAAA,CACf;AAED,QAAI,KAAK,iBAAiB;AACzB,YAAM,KAAK;IACX;AAED,WAAO;EACP,CAAA,CAAC;AAGI,SAAA,qBAAqB,OAAO,KAAK,QAAO;AACxC,UAAA,QAAQ,YAAY,KAAK,GAAG;AAE5B,UAAA,OAAO,QAAQ,KAAK;AAE1B,QAAI,IAAG;AAAA,EAAA,CACP;AACF;"}
package/dist/errors.cjs CHANGED
@@ -45,7 +45,11 @@ class InternalError extends SliceMachineError {
45
45
  }
46
46
  }
47
47
  const isSliceMachineError = (error) => {
48
- return typeof error === "object" && error !== null && "_sliceMachineError" in error;
48
+ if (typeof window !== "undefined") {
49
+ return typeof error === "object" && error !== null;
50
+ } else {
51
+ return typeof error === "object" && error !== null && "_sliceMachineError" in error;
52
+ }
49
53
  };
50
54
  const isUnauthorizedError = (error) => {
51
55
  return isSliceMachineError(error) && error.name === UnauthorizedError.name;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","sources":["../../src/errors.ts"],"sourcesContent":["import { HookError } from \"@slicemachine/plugin-kit\";\n\nexport class SliceMachineError extends Error {\n\t_sliceMachineError = true;\n\tname = \"SliceMachineError\";\n}\nexport class UnauthorizedError extends SliceMachineError {\n\tname = \"UnauthorizedError\";\n}\nexport class UnauthenticatedError extends SliceMachineError {\n\tname = \"UnauthenticatedError\";\n\tmessage = \"Authenticate before trying again.\";\n}\nexport class NotFoundError extends SliceMachineError {\n\tname = \"NotFoundError\";\n}\nexport class UnexpectedDataError extends SliceMachineError {\n\tname = \"UnexpectedDataError\";\n}\nexport class InternalError extends SliceMachineError {\n\tname = \"InternalError\";\n}\nexport class PluginError extends SliceMachineError {\n\tname = \"PluginError\";\n}\nexport class PluginHookResultError extends SliceMachineError {\n\tname = \"PluginHookResultError\";\n\n\tconstructor(errors: HookError[]) {\n\t\tsuper(\n\t\t\t`${errors.length} error${\n\t\t\t\terrors.length === 1 ? \"\" : \"s\"\n\t\t\t} were returned by one or more plugins.`,\n\t\t\t{\n\t\t\t\tcause: errors,\n\t\t\t},\n\t\t);\n\t}\n}\n\nexport const isSliceMachineError = (\n\terror: unknown,\n): error is SliceMachineError => {\n\treturn (\n\t\ttypeof error === \"object\" && error !== null && \"_sliceMachineError\" in error\n\t);\n};\n\nexport const isUnauthorizedError = (\n\terror: unknown,\n): error is UnauthorizedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthorizedError.name;\n};\n\nexport const isUnauthenticatedError = (\n\terror: unknown,\n): error is UnauthenticatedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthenticatedError.name;\n};\n\nexport const isNotFoundError = (error: unknown): error is NotFoundError => {\n\treturn isSliceMachineError(error) && error.name === NotFoundError.name;\n};\n\nexport const isUnexpectedDataError = (\n\terror: unknown,\n): error is UnexpectedDataError => {\n\treturn isSliceMachineError(error) && error.name === UnexpectedDataError.name;\n};\n\nexport const isInternalError = (error: unknown): error is InternalError => {\n\treturn isSliceMachineError(error) && error.name === InternalError.name;\n};\n"],"names":[],"mappings":";;;;;;;;AAEM,MAAO,0BAA0B,MAAK;AAAA,EAAtC;AAAA;AACL,8CAAqB;AACrB,gCAAO;AAAA;AACP;AACK,MAAO,0BAA0B,kBAAiB;AAAA,EAAlD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,6BAA6B,kBAAiB;AAAA,EAArD;AAAA;AACL,gCAAO;AACP,mCAAU;AAAA;AACV;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,4BAA4B,kBAAiB;AAAA,EAApD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AAmBY,MAAA,sBAAsB,CAClC,UAC+B;AAC/B,SACC,OAAO,UAAU,YAAY,UAAU,QAAQ,wBAAwB;AAEzE;AAEa,MAAA,sBAAsB,CAClC,UAC+B;AAC/B,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,kBAAkB;AACvE;AAEa,MAAA,yBAAyB,CACrC,UACkC;AAClC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,qBAAqB;AAC1E;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;AAEa,MAAA,wBAAwB,CACpC,UACiC;AACjC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,oBAAoB;AACzE;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"errors.cjs","sources":["../../src/errors.ts"],"sourcesContent":["import { HookError } from \"@slicemachine/plugin-kit\";\n\nexport class SliceMachineError extends Error {\n\t_sliceMachineError = true;\n\tname = \"SliceMachineError\";\n}\nexport class UnauthorizedError extends SliceMachineError {\n\tname = \"UnauthorizedError\";\n}\nexport class UnauthenticatedError extends SliceMachineError {\n\tname = \"UnauthenticatedError\";\n\tmessage = \"Authenticate before trying again.\";\n}\nexport class NotFoundError extends SliceMachineError {\n\tname = \"NotFoundError\";\n}\nexport class UnexpectedDataError extends SliceMachineError {\n\tname = \"UnexpectedDataError\";\n}\nexport class InternalError extends SliceMachineError {\n\tname = \"InternalError\";\n}\nexport class PluginError extends SliceMachineError {\n\tname = \"PluginError\";\n}\nexport class PluginHookResultError extends SliceMachineError {\n\tname = \"PluginHookResultError\";\n\n\tconstructor(errors: HookError[]) {\n\t\tsuper(\n\t\t\t`${errors.length} error${\n\t\t\t\terrors.length === 1 ? \"\" : \"s\"\n\t\t\t} were returned by one or more plugins.`,\n\t\t\t{\n\t\t\t\tcause: errors,\n\t\t\t},\n\t\t);\n\t}\n}\n\nexport const isSliceMachineError = (\n\terror: unknown,\n): error is SliceMachineError => {\n\t// TODO: Discuss a stronger way to serialize error for the client to detect with r19\n\t// @ts-expect-error We don't want to add \"dom\" to tsconfig \"lib\" because of the TODO\n\tif (typeof window !== \"undefined\") {\n\t\treturn typeof error === \"object\" && error !== null;\n\t} else {\n\t\treturn (\n\t\t\ttypeof error === \"object\" &&\n\t\t\terror !== null &&\n\t\t\t\"_sliceMachineError\" in error\n\t\t);\n\t}\n};\n\nexport const isUnauthorizedError = (\n\terror: unknown,\n): error is UnauthorizedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthorizedError.name;\n};\n\nexport const isUnauthenticatedError = (\n\terror: unknown,\n): error is UnauthenticatedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthenticatedError.name;\n};\n\nexport const isNotFoundError = (error: unknown): error is NotFoundError => {\n\treturn isSliceMachineError(error) && error.name === NotFoundError.name;\n};\n\nexport const isUnexpectedDataError = (\n\terror: unknown,\n): error is UnexpectedDataError => {\n\treturn isSliceMachineError(error) && error.name === UnexpectedDataError.name;\n};\n\nexport const isInternalError = (error: unknown): error is InternalError => {\n\treturn isSliceMachineError(error) && error.name === InternalError.name;\n};\n"],"names":[],"mappings":";;;;;;;;AAEM,MAAO,0BAA0B,MAAK;AAAA,EAAtC;AAAA;AACL,8CAAqB;AACrB,gCAAO;AAAA;AACP;AACK,MAAO,0BAA0B,kBAAiB;AAAA,EAAlD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,6BAA6B,kBAAiB;AAAA,EAArD;AAAA;AACL,gCAAO;AACP,mCAAU;AAAA;AACV;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,4BAA4B,kBAAiB;AAAA,EAApD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AAmBY,MAAA,sBAAsB,CAClC,UAC+B;AAG3B,MAAA,OAAO,WAAW,aAAa;AAC3B,WAAA,OAAO,UAAU,YAAY,UAAU;AAAA,EAAA,OACxC;AACN,WACC,OAAO,UAAU,YACjB,UAAU,QACV,wBAAwB;AAAA,EAEzB;AACF;AAEa,MAAA,sBAAsB,CAClC,UAC+B;AAC/B,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,kBAAkB;AACvE;AAEa,MAAA,yBAAyB,CACrC,UACkC;AAClC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,qBAAqB;AAC1E;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;AAEa,MAAA,wBAAwB,CACpC,UACiC;AACjC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,oBAAoB;AACzE;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;;;;;;;;;;;;;"}
package/dist/errors.js CHANGED
@@ -43,7 +43,11 @@ class InternalError extends SliceMachineError {
43
43
  }
44
44
  }
45
45
  const isSliceMachineError = (error) => {
46
- return typeof error === "object" && error !== null && "_sliceMachineError" in error;
46
+ if (typeof window !== "undefined") {
47
+ return typeof error === "object" && error !== null;
48
+ } else {
49
+ return typeof error === "object" && error !== null && "_sliceMachineError" in error;
50
+ }
47
51
  };
48
52
  const isUnauthorizedError = (error) => {
49
53
  return isSliceMachineError(error) && error.name === UnauthorizedError.name;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sources":["../../src/errors.ts"],"sourcesContent":["import { HookError } from \"@slicemachine/plugin-kit\";\n\nexport class SliceMachineError extends Error {\n\t_sliceMachineError = true;\n\tname = \"SliceMachineError\";\n}\nexport class UnauthorizedError extends SliceMachineError {\n\tname = \"UnauthorizedError\";\n}\nexport class UnauthenticatedError extends SliceMachineError {\n\tname = \"UnauthenticatedError\";\n\tmessage = \"Authenticate before trying again.\";\n}\nexport class NotFoundError extends SliceMachineError {\n\tname = \"NotFoundError\";\n}\nexport class UnexpectedDataError extends SliceMachineError {\n\tname = \"UnexpectedDataError\";\n}\nexport class InternalError extends SliceMachineError {\n\tname = \"InternalError\";\n}\nexport class PluginError extends SliceMachineError {\n\tname = \"PluginError\";\n}\nexport class PluginHookResultError extends SliceMachineError {\n\tname = \"PluginHookResultError\";\n\n\tconstructor(errors: HookError[]) {\n\t\tsuper(\n\t\t\t`${errors.length} error${\n\t\t\t\terrors.length === 1 ? \"\" : \"s\"\n\t\t\t} were returned by one or more plugins.`,\n\t\t\t{\n\t\t\t\tcause: errors,\n\t\t\t},\n\t\t);\n\t}\n}\n\nexport const isSliceMachineError = (\n\terror: unknown,\n): error is SliceMachineError => {\n\treturn (\n\t\ttypeof error === \"object\" && error !== null && \"_sliceMachineError\" in error\n\t);\n};\n\nexport const isUnauthorizedError = (\n\terror: unknown,\n): error is UnauthorizedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthorizedError.name;\n};\n\nexport const isUnauthenticatedError = (\n\terror: unknown,\n): error is UnauthenticatedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthenticatedError.name;\n};\n\nexport const isNotFoundError = (error: unknown): error is NotFoundError => {\n\treturn isSliceMachineError(error) && error.name === NotFoundError.name;\n};\n\nexport const isUnexpectedDataError = (\n\terror: unknown,\n): error is UnexpectedDataError => {\n\treturn isSliceMachineError(error) && error.name === UnexpectedDataError.name;\n};\n\nexport const isInternalError = (error: unknown): error is InternalError => {\n\treturn isSliceMachineError(error) && error.name === InternalError.name;\n};\n"],"names":[],"mappings":";;;;;;AAEM,MAAO,0BAA0B,MAAK;AAAA,EAAtC;AAAA;AACL,8CAAqB;AACrB,gCAAO;AAAA;AACP;AACK,MAAO,0BAA0B,kBAAiB;AAAA,EAAlD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,6BAA6B,kBAAiB;AAAA,EAArD;AAAA;AACL,gCAAO;AACP,mCAAU;AAAA;AACV;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,4BAA4B,kBAAiB;AAAA,EAApD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AAmBY,MAAA,sBAAsB,CAClC,UAC+B;AAC/B,SACC,OAAO,UAAU,YAAY,UAAU,QAAQ,wBAAwB;AAEzE;AAEa,MAAA,sBAAsB,CAClC,UAC+B;AAC/B,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,kBAAkB;AACvE;AAEa,MAAA,yBAAyB,CACrC,UACkC;AAClC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,qBAAqB;AAC1E;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;AAEa,MAAA,wBAAwB,CACpC,UACiC;AACjC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,oBAAoB;AACzE;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;"}
1
+ {"version":3,"file":"errors.js","sources":["../../src/errors.ts"],"sourcesContent":["import { HookError } from \"@slicemachine/plugin-kit\";\n\nexport class SliceMachineError extends Error {\n\t_sliceMachineError = true;\n\tname = \"SliceMachineError\";\n}\nexport class UnauthorizedError extends SliceMachineError {\n\tname = \"UnauthorizedError\";\n}\nexport class UnauthenticatedError extends SliceMachineError {\n\tname = \"UnauthenticatedError\";\n\tmessage = \"Authenticate before trying again.\";\n}\nexport class NotFoundError extends SliceMachineError {\n\tname = \"NotFoundError\";\n}\nexport class UnexpectedDataError extends SliceMachineError {\n\tname = \"UnexpectedDataError\";\n}\nexport class InternalError extends SliceMachineError {\n\tname = \"InternalError\";\n}\nexport class PluginError extends SliceMachineError {\n\tname = \"PluginError\";\n}\nexport class PluginHookResultError extends SliceMachineError {\n\tname = \"PluginHookResultError\";\n\n\tconstructor(errors: HookError[]) {\n\t\tsuper(\n\t\t\t`${errors.length} error${\n\t\t\t\terrors.length === 1 ? \"\" : \"s\"\n\t\t\t} were returned by one or more plugins.`,\n\t\t\t{\n\t\t\t\tcause: errors,\n\t\t\t},\n\t\t);\n\t}\n}\n\nexport const isSliceMachineError = (\n\terror: unknown,\n): error is SliceMachineError => {\n\t// TODO: Discuss a stronger way to serialize error for the client to detect with r19\n\t// @ts-expect-error We don't want to add \"dom\" to tsconfig \"lib\" because of the TODO\n\tif (typeof window !== \"undefined\") {\n\t\treturn typeof error === \"object\" && error !== null;\n\t} else {\n\t\treturn (\n\t\t\ttypeof error === \"object\" &&\n\t\t\terror !== null &&\n\t\t\t\"_sliceMachineError\" in error\n\t\t);\n\t}\n};\n\nexport const isUnauthorizedError = (\n\terror: unknown,\n): error is UnauthorizedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthorizedError.name;\n};\n\nexport const isUnauthenticatedError = (\n\terror: unknown,\n): error is UnauthenticatedError => {\n\treturn isSliceMachineError(error) && error.name === UnauthenticatedError.name;\n};\n\nexport const isNotFoundError = (error: unknown): error is NotFoundError => {\n\treturn isSliceMachineError(error) && error.name === NotFoundError.name;\n};\n\nexport const isUnexpectedDataError = (\n\terror: unknown,\n): error is UnexpectedDataError => {\n\treturn isSliceMachineError(error) && error.name === UnexpectedDataError.name;\n};\n\nexport const isInternalError = (error: unknown): error is InternalError => {\n\treturn isSliceMachineError(error) && error.name === InternalError.name;\n};\n"],"names":[],"mappings":";;;;;;AAEM,MAAO,0BAA0B,MAAK;AAAA,EAAtC;AAAA;AACL,8CAAqB;AACrB,gCAAO;AAAA;AACP;AACK,MAAO,0BAA0B,kBAAiB;AAAA,EAAlD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,6BAA6B,kBAAiB;AAAA,EAArD;AAAA;AACL,gCAAO;AACP,mCAAU;AAAA;AACV;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,4BAA4B,kBAAiB;AAAA,EAApD;AAAA;AACL,gCAAO;AAAA;AACP;AACK,MAAO,sBAAsB,kBAAiB;AAAA,EAA9C;AAAA;AACL,gCAAO;AAAA;AACP;AAmBY,MAAA,sBAAsB,CAClC,UAC+B;AAG3B,MAAA,OAAO,WAAW,aAAa;AAC3B,WAAA,OAAO,UAAU,YAAY,UAAU;AAAA,EAAA,OACxC;AACN,WACC,OAAO,UAAU,YACjB,UAAU,QACV,wBAAwB;AAAA,EAEzB;AACF;AAEa,MAAA,sBAAsB,CAClC,UAC+B;AAC/B,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,kBAAkB;AACvE;AAEa,MAAA,yBAAyB,CACrC,UACkC;AAClC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,qBAAqB;AAC1E;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;AAEa,MAAA,wBAAwB,CACpC,UACiC;AACjC,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,oBAAoB;AACzE;AAEa,MAAA,kBAAkB,CAAC,UAA0C;AACzE,SAAO,oBAAoB,KAAK,KAAK,MAAM,SAAS,cAAc;AACnE;"}
@@ -6,6 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  return value;
7
7
  };
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
+ const prismicCustomTypesClient = require("@prismicio/custom-types-client");
9
10
  const createContentDigest = require("../lib/createContentDigest.cjs");
10
11
  const createPrismicAuthManager = require("../auth/createPrismicAuthManager.cjs");
11
12
  const API_ENDPOINTS = require("../constants/API_ENDPOINTS.cjs");
@@ -76,40 +77,55 @@ class SliceMachineManager {
76
77
  // potential source of bugs due to data inconsistency. SM UI relies on
77
78
  // it heavily, so removal will require significant effort.
78
79
  async getState() {
79
- const [{ sliceMachineConfig, libraries }, { profile, remoteCustomTypes, remoteSlices }, customTypes, packageManager] = await Promise.all([
80
+ const [{ sliceMachineConfig, libraries }, { profile, remoteCustomTypes, remoteSlices, authError }, customTypes, packageManager] = await Promise.all([
80
81
  this.project.getSliceMachineConfig().then(async (sliceMachineConfig2) => {
81
82
  const libraries2 = await this._getLibraries(sliceMachineConfig2);
82
83
  return { sliceMachineConfig: sliceMachineConfig2, libraries: libraries2 };
83
84
  }),
84
85
  this._getProfile().then(async (profile2) => {
86
+ let authError2;
85
87
  if (profile2) {
86
- const [remoteCustomTypes2, remoteSlices2] = await Promise.all([
87
- this.customTypes.fetchRemoteCustomTypes(),
88
- this.slices.fetchRemoteSlices()
89
- ]);
90
- return {
91
- profile: profile2,
92
- remoteCustomTypes: remoteCustomTypes2,
93
- remoteSlices: remoteSlices2
94
- };
95
- } else {
96
- return {
97
- profile: profile2,
98
- remoteCustomTypes: [],
99
- remoteSlices: []
100
- };
88
+ try {
89
+ const [remoteCustomTypes2, remoteSlices2] = await Promise.all([
90
+ this.customTypes.fetchRemoteCustomTypes(),
91
+ this.slices.fetchRemoteSlices()
92
+ ]);
93
+ return {
94
+ profile: profile2,
95
+ remoteCustomTypes: remoteCustomTypes2,
96
+ remoteSlices: remoteSlices2,
97
+ authError: authError2
98
+ };
99
+ } catch (error) {
100
+ if (error instanceof prismicCustomTypesClient.UnauthorizedError || error instanceof prismicCustomTypesClient.ForbiddenError) {
101
+ authError2 = {
102
+ name: "__stub__",
103
+ message: "__stub__",
104
+ reason: "__stub__",
105
+ status: 401
106
+ };
107
+ } else {
108
+ throw error;
109
+ }
110
+ }
101
111
  }
112
+ return {
113
+ profile: profile2,
114
+ remoteCustomTypes: [],
115
+ remoteSlices: [],
116
+ authError: authError2
117
+ };
102
118
  }),
103
119
  this._getCustomTypes(),
104
120
  this.project.detectPackageManager()
105
121
  ]);
106
- const clientError = profile ? void 0 : {
122
+ const clientError = authError || (profile ? void 0 : {
107
123
  name: "__stub__",
108
124
  message: "__stub__",
109
125
  reason: "__stub__",
110
126
  status: 401
111
127
  // Needed to trigger the unauthorized flow.
112
- };
128
+ });
113
129
  return {
114
130
  env: {
115
131
  manifest: {
@@ -117,6 +133,7 @@ class SliceMachineManager {
117
133
  localSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL
118
134
  },
119
135
  packageManager,
136
+ supportsSliceSimulator: this.simulator.supportsSliceSimulator(),
120
137
  repo: sliceMachineConfig.repositoryName,
121
138
  intercomHash: profile == null ? void 0 : profile.intercomHash,
122
139
  shortId: profile == null ? void 0 : profile.shortId
@@ -1 +1 @@
1
- {"version":3,"file":"SliceMachineManager.cjs","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import { CustomTypes } from \"@prismicio/types-internal\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageChangelog, PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tchangelog?: PackageChangelog;\n\t\tpackageManager: PackageManager;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: CustomTypes.Widgets.Slices.SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmock?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomTypes.CustomType[];\n\tremoteCustomTypes: CustomTypes.CustomType[];\n\tremoteSlices: CustomTypes.Widgets.Slices.SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tif (profile) {\n\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t]);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tprofile,\n\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tprofile,\n\t\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// TODO: SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user is\n\t\t// not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tprofile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t };\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmock: mocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["createPrismicAuthManager","UserManager","PrismicRepositoryManager","PluginsManager","ProjectManager","CustomTypesManager","SlicesManager","SnippetsManager","ScreenshotsManager","SimulatorManager","VersionsManager","TelemetryManager","API_ENDPOINTS","sliceMachineConfig","libraries","profile","remoteCustomTypes","remoteSlices","buildPrismicRepositoryAPIEndpoint","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;MA2Fa,oBAAmB;AAAA,EAmB/B,YAAY,MAAyC;AAlB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsBA,yBAAAA;AAEtB,SAAA,OAAO,IAAIC,YAAA,YAAY,IAAI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B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;;"}
1
+ {"version":3,"file":"SliceMachineManager.cjs","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import { CustomTypes } from \"@prismicio/types-internal\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tForbiddenError,\n\tUnauthorizedError,\n} from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageChangelog, PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tchangelog?: PackageChangelog;\n\t\tpackageManager: PackageManager;\n\t\tsupportsSliceSimulator: boolean;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: CustomTypes.Widgets.Slices.SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmock?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomTypes.CustomType[];\n\tremoteCustomTypes: CustomTypes.CustomType[];\n\tremoteSlices: CustomTypes.Widgets.Slices.SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Non-Prismic error\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof UnauthorizedError ||\n\t\t\t\t\t\t\terror instanceof ForbiddenError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\tsupportsSliceSimulator: this.simulator.supportsSliceSimulator(),\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmock: mocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["createPrismicAuthManager","UserManager","PrismicRepositoryManager","PluginsManager","ProjectManager","CustomTypesManager","SlicesManager","SnippetsManager","ScreenshotsManager","SimulatorManager","VersionsManager","TelemetryManager","API_ENDPOINTS","sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices","UnauthorizedError","ForbiddenError","buildPrismicRepositoryAPIEndpoint","createContentDigest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;MAgGa,oBAAmB;AAAA,EAmB/B,YAAY,MAAyC;AAlB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsBA,yBAAAA;AAEtB,SAAA,OAAO,IAAIC,YAAA,YAAY,IA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AAA,YACN,SAAS;AAAA,YACT;AAAA,YACA,MAAM;AAAA;AAAA,cAEL,cAAc;AAAA,cACd,cAAc;AAAA,cACd,UAAU;AAAA,YACV;AAAA,UAAA,CACD;AAAA,QACD;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAGD,WAAO,UAAU,KAAK,CAAC,UAAU,aAAY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;;"}
@@ -27,6 +27,7 @@ type SliceMachineManagerGetStateReturnType = {
27
27
  repo: string;
28
28
  changelog?: PackageChangelog;
29
29
  packageManager: PackageManager;
30
+ supportsSliceSimulator: boolean;
30
31
  };
31
32
  libraries: {
32
33
  name: string;
@@ -4,6 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
+ import { UnauthorizedError, ForbiddenError } from "@prismicio/custom-types-client";
7
8
  import { createContentDigest } from "../lib/createContentDigest.js";
8
9
  import { createPrismicAuthManager } from "../auth/createPrismicAuthManager.js";
9
10
  import { API_ENDPOINTS } from "../constants/API_ENDPOINTS.js";
@@ -74,40 +75,55 @@ class SliceMachineManager {
74
75
  // potential source of bugs due to data inconsistency. SM UI relies on
75
76
  // it heavily, so removal will require significant effort.
76
77
  async getState() {
77
- const [{ sliceMachineConfig, libraries }, { profile, remoteCustomTypes, remoteSlices }, customTypes, packageManager] = await Promise.all([
78
+ const [{ sliceMachineConfig, libraries }, { profile, remoteCustomTypes, remoteSlices, authError }, customTypes, packageManager] = await Promise.all([
78
79
  this.project.getSliceMachineConfig().then(async (sliceMachineConfig2) => {
79
80
  const libraries2 = await this._getLibraries(sliceMachineConfig2);
80
81
  return { sliceMachineConfig: sliceMachineConfig2, libraries: libraries2 };
81
82
  }),
82
83
  this._getProfile().then(async (profile2) => {
84
+ let authError2;
83
85
  if (profile2) {
84
- const [remoteCustomTypes2, remoteSlices2] = await Promise.all([
85
- this.customTypes.fetchRemoteCustomTypes(),
86
- this.slices.fetchRemoteSlices()
87
- ]);
88
- return {
89
- profile: profile2,
90
- remoteCustomTypes: remoteCustomTypes2,
91
- remoteSlices: remoteSlices2
92
- };
93
- } else {
94
- return {
95
- profile: profile2,
96
- remoteCustomTypes: [],
97
- remoteSlices: []
98
- };
86
+ try {
87
+ const [remoteCustomTypes2, remoteSlices2] = await Promise.all([
88
+ this.customTypes.fetchRemoteCustomTypes(),
89
+ this.slices.fetchRemoteSlices()
90
+ ]);
91
+ return {
92
+ profile: profile2,
93
+ remoteCustomTypes: remoteCustomTypes2,
94
+ remoteSlices: remoteSlices2,
95
+ authError: authError2
96
+ };
97
+ } catch (error) {
98
+ if (error instanceof UnauthorizedError || error instanceof ForbiddenError) {
99
+ authError2 = {
100
+ name: "__stub__",
101
+ message: "__stub__",
102
+ reason: "__stub__",
103
+ status: 401
104
+ };
105
+ } else {
106
+ throw error;
107
+ }
108
+ }
99
109
  }
110
+ return {
111
+ profile: profile2,
112
+ remoteCustomTypes: [],
113
+ remoteSlices: [],
114
+ authError: authError2
115
+ };
100
116
  }),
101
117
  this._getCustomTypes(),
102
118
  this.project.detectPackageManager()
103
119
  ]);
104
- const clientError = profile ? void 0 : {
120
+ const clientError = authError || (profile ? void 0 : {
105
121
  name: "__stub__",
106
122
  message: "__stub__",
107
123
  reason: "__stub__",
108
124
  status: 401
109
125
  // Needed to trigger the unauthorized flow.
110
- };
126
+ });
111
127
  return {
112
128
  env: {
113
129
  manifest: {
@@ -115,6 +131,7 @@ class SliceMachineManager {
115
131
  localSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL
116
132
  },
117
133
  packageManager,
134
+ supportsSliceSimulator: this.simulator.supportsSliceSimulator(),
118
135
  repo: sliceMachineConfig.repositoryName,
119
136
  intercomHash: profile == null ? void 0 : profile.intercomHash,
120
137
  shortId: profile == null ? void 0 : profile.shortId
@@ -1 +1 @@
1
- {"version":3,"file":"SliceMachineManager.js","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import { CustomTypes } from \"@prismicio/types-internal\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageChangelog, PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tchangelog?: PackageChangelog;\n\t\tpackageManager: PackageManager;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: CustomTypes.Widgets.Slices.SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmock?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomTypes.CustomType[];\n\tremoteCustomTypes: CustomTypes.CustomType[];\n\tremoteSlices: CustomTypes.Widgets.Slices.SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tif (profile) {\n\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t]);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tprofile,\n\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tprofile,\n\t\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// TODO: SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user is\n\t\t// not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tprofile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t };\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmock: mocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["sliceMachineConfig","libraries","profile","remoteCustomTypes","remoteSlices"],"mappings":";;;;;;;;;;;;;;;;;;;;;MA2Fa,oBAAmB;AAAA,EAmB/B,YAAY,MAAyC;AAlB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMC,SAAK,sBAAsB;AAEtB,SAAA,OAAO,IAAI,YAAY,IAAI;AAC3B,SAAA,oBAAoB,IAAI,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAI,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAI,eAAe,IAAI;AACjC,SAAA,cAAc,IAAI,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAI,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAI,gBAAgB,IAAI;AACnC,SAAA,cAAc,IAAI,mBAAmB,IAAI;AACzC,SAAA,YAAY,IAAI,iBAAiB,IAAI;AAErC,SAAA,WAAW,IAAI,gBAAgB,IAAI;AAEnC,SAAA,YAAY,IAAI,iBAAiB,IAAI;AAE1C,SAAK,OAAM,6BAAM,QAAO,QAAQ,IAAG;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,8BAA2B;AAC1B,WAAO,KAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,wBAAqB;AACpB,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,kBAAe;AACP,WAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAQ;AACb,UAAM,CACL,EAAE,oBAAoB,aACtB,EAAE,SAAS,mBAAmB,aAAA,GAC9B,aACA,cAAc,IACX,MAAM,QAAQ,IAAI;AAAA,MACrB,KAAK,QAAQ,sBAAwB,E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A,cAEL,cAAc;AAAA,cACd,cAAc;AAAA,cACd,UAAU;AAAA,YACV;AAAA,UAAA,CACD;AAAA,QACD;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAGD,WAAO,UAAU,KAAK,CAAC,UAAU,aAAY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;"}
1
+ {"version":3,"file":"SliceMachineManager.js","sources":["../../../src/managers/SliceMachineManager.ts"],"sourcesContent":["import { CustomTypes } from \"@prismicio/types-internal\";\nimport { SharedSliceContent } from \"@prismicio/types-internal/lib/content\";\nimport {\n\tForbiddenError,\n\tUnauthorizedError,\n} from \"@prismicio/custom-types-client\";\nimport {\n\tSliceMachinePlugin,\n\tSliceMachinePluginRunner,\n} from \"@slicemachine/plugin-kit\";\n\nimport { createContentDigest } from \"../lib/createContentDigest\";\n\nimport { PackageChangelog, PackageManager, SliceMachineConfig } from \"../types\";\nimport {\n\tPrismicAuthManager,\n\tPrismicUserProfile,\n} from \"../auth/PrismicAuthManager\";\nimport { createPrismicAuthManager } from \"../auth/createPrismicAuthManager\";\n\nimport { API_ENDPOINTS, APIEndpoints } from \"../constants/API_ENDPOINTS\";\n\nimport { UserManager } from \"./user/UserManager\";\nimport { PrismicRepositoryManager } from \"./prismicRepository/PrismicRepositoryManager\";\n\nimport { PluginsManager } from \"./plugins/PluginsManager\";\n\nimport { ProjectManager } from \"./project/ProjectManager\";\nimport { CustomTypesManager } from \"./customTypes/CustomTypesManager\";\nimport { SlicesManager } from \"./slices/SlicesManager\";\nimport { SnippetsManager } from \"./snippets/SnippetsManager\";\nimport { ScreenshotsManager } from \"./screenshots/ScreenshotsManager\";\nimport { SimulatorManager } from \"./simulator/SimulatorManager\";\n\nimport { VersionsManager } from \"./versions/VersionsManager\";\n\nimport { TelemetryManager } from \"./telemetry/TelemetryManager\";\nimport { buildPrismicRepositoryAPIEndpoint } from \"../lib/buildPrismicRepositoryAPIEndpoint\";\n\ntype SliceMachineManagerGetStateReturnType = {\n\tenv: {\n\t\tshortId?: string;\n\t\tintercomHash?: string;\n\t\tmanifest: {\n\t\t\tapiEndpoint: string;\n\t\t\tlocalSliceSimulatorURL?: string;\n\t\t};\n\t\trepo: string;\n\t\tchangelog?: PackageChangelog;\n\t\tpackageManager: PackageManager;\n\t\tsupportsSliceSimulator: boolean;\n\t};\n\tlibraries: {\n\t\tname: string;\n\t\tpath: string;\n\t\tisLocal: boolean;\n\t\tcomponents: {\n\t\t\tfrom: string;\n\t\t\thref: string;\n\t\t\tpathToSlice: string;\n\t\t\tfileName: string | null;\n\t\t\textension: string | null;\n\t\t\tmodel: CustomTypes.Widgets.Slices.SharedSlice;\n\t\t\tscreenshots: Record<\n\t\t\t\tstring,\n\t\t\t\t{\n\t\t\t\t\thash: string;\n\t\t\t\t\tdata: Buffer;\n\t\t\t\t}\n\t\t\t>;\n\t\t\tmock?: SharedSliceContent[];\n\t\t}[];\n\t\tmeta: {\n\t\t\tname?: string;\n\t\t\tversion?: string;\n\t\t\tisNodeModule: boolean;\n\t\t\tisDownloaded: boolean;\n\t\t\tisManual: boolean;\n\t\t};\n\t}[];\n\tcustomTypes: CustomTypes.CustomType[];\n\tremoteCustomTypes: CustomTypes.CustomType[];\n\tremoteSlices: CustomTypes.Widgets.Slices.SharedSlice[];\n\tclientError?: {\n\t\tname: string;\n\t\tmessage: string;\n\t\tstatus: number;\n\t\treason: string;\n\t};\n};\n\ntype SliceMachineManagerConstructorArgs = {\n\tcwd?: string;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\nexport class SliceMachineManager {\n\tprivate _sliceMachinePluginRunner: SliceMachinePluginRunner | undefined =\n\t\tundefined;\n\tprivate _prismicAuthManager: PrismicAuthManager;\n\n\tcwd: string;\n\n\tcustomTypes: CustomTypesManager;\n\tplugins: PluginsManager;\n\tprismicRepository: PrismicRepositoryManager;\n\tproject: ProjectManager;\n\tscreenshots: ScreenshotsManager;\n\tsimulator: SimulatorManager;\n\tslices: SlicesManager;\n\tsnippets: SnippetsManager;\n\ttelemetry: TelemetryManager;\n\tuser: UserManager;\n\tversions: VersionsManager;\n\n\tconstructor(args?: SliceMachineManagerConstructorArgs) {\n\t\t// _prismicAuthManager must be set at least before UserManager\n\t\t// is instantiated. It depends on the PrismicAuthManager for\n\t\t// authentication-related methods.\n\t\tthis._prismicAuthManager = createPrismicAuthManager();\n\n\t\tthis.user = new UserManager(this);\n\t\tthis.prismicRepository = new PrismicRepositoryManager(this);\n\n\t\tthis.plugins = new PluginsManager(this, {\n\t\t\tnativePlugins: args?.nativePlugins,\n\t\t});\n\n\t\tthis.project = new ProjectManager(this);\n\t\tthis.customTypes = new CustomTypesManager(this);\n\t\tthis.slices = new SlicesManager(this);\n\t\tthis.snippets = new SnippetsManager(this);\n\t\tthis.screenshots = new ScreenshotsManager(this);\n\t\tthis.simulator = new SimulatorManager(this);\n\n\t\tthis.versions = new VersionsManager(this);\n\n\t\tthis.telemetry = new TelemetryManager(this);\n\n\t\tthis.cwd = args?.cwd ?? process.cwd();\n\t}\n\n\t// The `_sliceMachinePluginRunner` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat SliceMachinePluginRunner\n\t// as a child manager.\n\tgetSliceMachinePluginRunner(): SliceMachinePluginRunner | undefined {\n\t\treturn this._sliceMachinePluginRunner;\n\t}\n\n\t// The `_prismicAuthManager` property is hidden behind a function to\n\t// discourage access. Using a function deliberatly breaks the pattern\n\t// of other child managers that are accessible as properties, like\n\t// `project`, `plugins`, etc. We do not treat PrismicAuthManager as a\n\t// child manager.\n\tgetPrismicAuthManager(): PrismicAuthManager {\n\t\treturn this._prismicAuthManager;\n\t}\n\n\tgetAPIEndpoints(): APIEndpoints {\n\t\treturn API_ENDPOINTS;\n\t}\n\n\t// TODO: Remove this global-state method. It is expensive and a\n\t// potential source of bugs due to data inconsistency. SM UI relies on\n\t// it heavily, so removal will require significant effort.\n\tasync getState(): Promise<SliceMachineManagerGetStateReturnType> {\n\t\tconst [\n\t\t\t{ sliceMachineConfig, libraries },\n\t\t\t{ profile, remoteCustomTypes, remoteSlices, authError },\n\t\t\tcustomTypes,\n\t\t\tpackageManager,\n\t\t] = await Promise.all([\n\t\t\tthis.project.getSliceMachineConfig().then(async (sliceMachineConfig) => {\n\t\t\t\tconst libraries = await this._getLibraries(sliceMachineConfig);\n\n\t\t\t\treturn { sliceMachineConfig, libraries };\n\t\t\t}),\n\t\t\tthis._getProfile().then(async (profile) => {\n\t\t\t\tlet authError;\n\t\t\t\tif (profile) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst [remoteCustomTypes, remoteSlices] = await Promise.all([\n\t\t\t\t\t\t\tthis.customTypes.fetchRemoteCustomTypes(),\n\t\t\t\t\t\t\tthis.slices.fetchRemoteSlices(),\n\t\t\t\t\t\t]);\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\tremoteCustomTypes,\n\t\t\t\t\t\t\tremoteSlices,\n\t\t\t\t\t\t\tauthError,\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Non-Prismic error\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\terror instanceof UnauthorizedError ||\n\t\t\t\t\t\t\terror instanceof ForbiddenError\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tauthError = {\n\t\t\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\t\t\tstatus: 401,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tprofile,\n\t\t\t\t\tremoteCustomTypes: [],\n\t\t\t\t\tremoteSlices: [],\n\t\t\t\t\tauthError,\n\t\t\t\t};\n\t\t\t}),\n\t\t\tthis._getCustomTypes(),\n\t\t\tthis.project.detectPackageManager(),\n\t\t]);\n\n\t\t// SM UI detects if a user is logged out by looking at\n\t\t// `clientError`. Here, we simulate what the old core does by\n\t\t// returning an `ErrorWithStatus`-like object if the user does\n\t\t// not have access to the repository or is not logged in.\n\t\tconst clientError: SliceMachineManagerGetStateReturnType[\"clientError\"] =\n\t\t\tauthError ||\n\t\t\t(profile\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tname: \"__stub__\",\n\t\t\t\t\t\tmessage: \"__stub__\",\n\t\t\t\t\t\treason: \"__stub__\",\n\t\t\t\t\t\tstatus: 401, // Needed to trigger the unauthorized flow.\n\t\t\t\t });\n\n\t\treturn {\n\t\t\tenv: {\n\t\t\t\tmanifest: {\n\t\t\t\t\tapiEndpoint:\n\t\t\t\t\t\tsliceMachineConfig.apiEndpoint ||\n\t\t\t\t\t\tbuildPrismicRepositoryAPIEndpoint(\n\t\t\t\t\t\t\tsliceMachineConfig.repositoryName,\n\t\t\t\t\t\t),\n\t\t\t\t\tlocalSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,\n\t\t\t\t},\n\t\t\t\tpackageManager,\n\t\t\t\tsupportsSliceSimulator: this.simulator.supportsSliceSimulator(),\n\t\t\t\trepo: sliceMachineConfig.repositoryName,\n\t\t\t\tintercomHash: profile?.intercomHash,\n\t\t\t\tshortId: profile?.shortId,\n\t\t\t},\n\t\t\tlibraries,\n\t\t\tcustomTypes,\n\t\t\tremoteCustomTypes,\n\t\t\tremoteSlices,\n\t\t\tclientError,\n\t\t};\n\t}\n\n\tprivate async _getProfile(): Promise<PrismicUserProfile | undefined> {\n\t\tlet profile: PrismicUserProfile | undefined;\n\n\t\tconst isLoggedIn = await this.user.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tprofile = await this.user.getProfile();\n\t\t\tawait this.user.refreshAuthenticationToken();\n\t\t}\n\n\t\treturn profile;\n\t}\n\n\tprivate async _getLibraries(\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t): Promise<SliceMachineManagerGetStateReturnType[\"libraries\"]> {\n\t\tconst libraries: SliceMachineManagerGetStateReturnType[\"libraries\"] = [];\n\n\t\tif (sliceMachineConfig.libraries) {\n\t\t\tawait Promise.all(\n\t\t\t\tsliceMachineConfig.libraries.map(async (libraryID) => {\n\t\t\t\t\tconst { sliceIDs } = await this.slices.readSliceLibrary({\n\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (sliceIDs) {\n\t\t\t\t\t\tconst components: SliceMachineManagerGetStateReturnType[\"libraries\"][number][\"components\"] =\n\t\t\t\t\t\t\t[];\n\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\t\t\t\t\tconst [{ model }, { mocks }] = await Promise.all([\n\t\t\t\t\t\t\t\t\tthis.slices.readSlice({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t\tthis.slices.readSliceMocks({ libraryID, sliceID }),\n\t\t\t\t\t\t\t\t]);\n\n\t\t\t\t\t\t\t\tif (model) {\n\t\t\t\t\t\t\t\t\tconst screenshots: (typeof components)[number][\"screenshots\"] =\n\t\t\t\t\t\t\t\t\t\t{};\n\t\t\t\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\t\t\t\tmodel.variations.map(async (variation) => {\n\t\t\t\t\t\t\t\t\t\t\tconst screenshot = await this.slices.readSliceScreenshot({\n\t\t\t\t\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t\t\t\t\tsliceID,\n\t\t\t\t\t\t\t\t\t\t\t\tvariationID: variation.id,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (screenshot.data) {\n\t\t\t\t\t\t\t\t\t\t\t\tscreenshots[variation.id] = {\n\t\t\t\t\t\t\t\t\t\t\t\t\thash: createContentDigest(screenshot.data),\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: screenshot.data,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\tcomponents.push({\n\t\t\t\t\t\t\t\t\t\tfrom: libraryID,\n\t\t\t\t\t\t\t\t\t\thref: libraryID.replace(/\\//g, \"--\"),\n\t\t\t\t\t\t\t\t\t\tpathToSlice: \"pathToSlice\",\n\t\t\t\t\t\t\t\t\t\tfileName: \"fileName\",\n\t\t\t\t\t\t\t\t\t\textension: \"extension\",\n\t\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\t\tscreenshots,\n\t\t\t\t\t\t\t\t\t\tmock: mocks,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlibraries.push({\n\t\t\t\t\t\t\tname: libraryID,\n\t\t\t\t\t\t\tpath: libraryID,\n\t\t\t\t\t\t\tisLocal: true, // TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\tcomponents,\n\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t// TODO: Do we still support node_modules-based libraries?\n\t\t\t\t\t\t\t\tisNodeModule: false,\n\t\t\t\t\t\t\t\tisDownloaded: false,\n\t\t\t\t\t\t\t\tisManual: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// Preserve library order from config file\n\t\treturn libraries.sort((library1, library2) => {\n\t\t\tconst libraryIndex1 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library1.name) || 0;\n\t\t\tconst libraryIndex2 =\n\t\t\t\tsliceMachineConfig.libraries?.indexOf(library2.name) || 0;\n\n\t\t\treturn Math.sign(libraryIndex1 - libraryIndex2);\n\t\t});\n\t}\n\n\tprivate async _getCustomTypes(): Promise<\n\t\tSliceMachineManagerGetStateReturnType[\"customTypes\"]\n\t> {\n\t\tconst customTypes: SliceMachineManagerGetStateReturnType[\"customTypes\"] =\n\t\t\t[];\n\n\t\tconst { ids: customTypeIDs } =\n\t\t\tawait this.customTypes.readCustomTypeLibrary();\n\n\t\tif (customTypeIDs) {\n\t\t\tawait Promise.all(\n\t\t\t\tcustomTypeIDs.map(async (customTypeID) => {\n\t\t\t\t\tconst { model } = await this.customTypes.readCustomType({\n\t\t\t\t\t\tid: customTypeID,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (model) {\n\t\t\t\t\t\tcustomTypes.push(model);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn customTypes;\n\t}\n}\n"],"names":["sliceMachineConfig","libraries","profile","authError","remoteCustomTypes","remoteSlices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;MAgGa,oBAAmB;AAAA,EAmB/B,YAAY,MAAyC;AAlB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;AAAA,cAEL,cAAc;AAAA,cACd,cAAc;AAAA,cACd,UAAU;AAAA,YACV;AAAA,UAAA,CACD;AAAA,QACD;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAGD,WAAO,UAAU,KAAK,CAAC,UAAU,aAAY;;AAC5C,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AACzD,YAAM,kBACL,wBAAmB,cAAnB,mBAA8B,QAAQ,SAAS,UAAS;AAElD,aAAA,KAAK,KAAK,gBAAgB,aAAa;AAAA,IAAA,CAC9C;AAAA,EACF;AAAA,EAEQ,MAAM,kBAAe;AAG5B,UAAM,cACL,CAAA;AAED,UAAM,EAAE,KAAK,kBACZ,MAAM,KAAK,YAAY;AAExB,QAAI,eAAe;AAClB,YAAM,QAAQ,IACb,cAAc,IAAI,OAAO,iBAAgB;AACxC,cAAM,EAAE,MAAK,IAAK,MAAM,KAAK,YAAY,eAAe;AAAA,UACvD,IAAI;AAAA,QAAA,CACJ;AAED,YAAI,OAAO;AACV,sBAAY,KAAK,KAAK;AAAA,QACtB;AAAA,MACD,CAAA,CAAC;AAAA,IAEH;AAEM,WAAA;AAAA,EACR;AACA;"}
@@ -280,30 +280,28 @@ class PrismicRepositoryManager extends BaseManager.BaseManager {
280
280
  confirmDeleteDocuments: args.confirmDeleteDocuments,
281
281
  changes: allChanges
282
282
  };
283
- const authenticationToken = await this.user.getAuthenticationToken();
284
283
  const sliceMachineConfig = await this.project.getSliceMachineConfig();
285
- return index.default("https://customtypes.prismic.io/bulk", {
286
- body: JSON.stringify(requestBody),
284
+ const response = await this._fetch({
285
+ url: new URL("/bulk", API_ENDPOINTS.API_ENDPOINTS.PrismicModels),
287
286
  method: "POST",
288
- headers: {
289
- Authorization: `Bearer ${authenticationToken}`,
290
- "User-Agent": "slice-machine",
291
- repository: sliceMachineConfig.repositoryName,
292
- "Content-Type": "application/json"
293
- }
294
- }).then(async (response) => {
295
- if (response.status === 204) {
296
- return null;
297
- }
298
- return this._decodeLimitOrThrow(await response.json(), response.status, types.LimitType.SOFT);
299
- }).catch((err) => {
300
- try {
301
- const data = JSON.parse(err.message);
302
- return this._decodeLimitOrThrow(data, err.status, types.LimitType.HARD);
303
- } catch {
304
- throw err;
305
- }
287
+ body: requestBody,
288
+ repository: sliceMachineConfig.repositoryName
306
289
  });
290
+ switch (response.status) {
291
+ case 202:
292
+ return this._decodeLimitOrThrow(await response.json(), response.status, types.LimitType.SOFT);
293
+ case 204:
294
+ return null;
295
+ case 401:
296
+ throw new errors.UnauthenticatedError();
297
+ case 403:
298
+ return this._decodeLimitOrThrow(await response.json(), response.status, types.LimitType.HARD);
299
+ case 400:
300
+ const text = await response.text();
301
+ throw new Error(text);
302
+ default:
303
+ throw new Error(`Unexpected status code ${response.status}`);
304
+ }
307
305
  } catch (err) {
308
306
  console.error("An error happened while pushing your changes");
309
307
  console.error(err);
@@ -328,6 +326,9 @@ class PrismicRepositoryManager extends BaseManager.BaseManager {
328
326
  if (args.body) {
329
327
  extraHeaders["Content-Type"] = "application/json";
330
328
  }
329
+ if (args.repository) {
330
+ extraHeaders.repository = args.repository;
331
+ }
331
332
  return await index.default(args.url.toString(), {
332
333
  method: args.method,
333
334
  body: args.body ? JSON.stringify(args.body) : void 0,