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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/constants/API_ENDPOINTS.cjs +6 -5
  2. package/dist/constants/API_ENDPOINTS.cjs.map +1 -1
  3. package/dist/constants/API_ENDPOINTS.js +6 -5
  4. package/dist/constants/API_ENDPOINTS.js.map +1 -1
  5. package/dist/lib/addTrailingSlash.cjs +7 -0
  6. package/dist/lib/addTrailingSlash.cjs.map +1 -0
  7. package/dist/lib/addTrailingSlash.d.ts +1 -0
  8. package/dist/lib/addTrailingSlash.js +7 -0
  9. package/dist/lib/addTrailingSlash.js.map +1 -0
  10. package/dist/managers/SliceMachineManager.cjs +7 -5
  11. package/dist/managers/SliceMachineManager.cjs.map +1 -1
  12. package/dist/managers/SliceMachineManager.d.ts +0 -2
  13. package/dist/managers/SliceMachineManager.js +7 -5
  14. package/dist/managers/SliceMachineManager.js.map +1 -1
  15. package/dist/managers/telemetry/TelemetryManager.cjs +39 -12
  16. package/dist/managers/telemetry/TelemetryManager.cjs.map +1 -1
  17. package/dist/managers/telemetry/TelemetryManager.d.ts +14 -1
  18. package/dist/managers/telemetry/TelemetryManager.js +39 -12
  19. package/dist/managers/telemetry/TelemetryManager.js.map +1 -1
  20. package/dist/managers/telemetry/types.cjs +0 -4
  21. package/dist/managers/telemetry/types.cjs.map +1 -1
  22. package/dist/managers/telemetry/types.d.ts +1 -18
  23. package/dist/managers/telemetry/types.js +0 -4
  24. package/dist/managers/telemetry/types.js.map +1 -1
  25. package/package.json +3 -3
  26. package/src/constants/API_ENDPOINTS.ts +8 -5
  27. package/src/lib/addTrailingSlash.ts +5 -0
  28. package/src/managers/SliceMachineManager.ts +9 -5
  29. package/src/managers/telemetry/TelemetryManager.ts +77 -13
  30. package/src/managers/telemetry/types.ts +3 -26
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const addTrailingSlash = require("../lib/addTrailingSlash.cjs");
3
4
  const APPLICATION_MODE = require("./APPLICATION_MODE.cjs");
4
5
  const API_ENDPOINTS = (() => {
5
6
  switch (process.env.SM_ENV) {
6
7
  case APPLICATION_MODE.APPLICATION_MODE.Development: {
7
8
  const apiEndpoints = {
8
- PrismicWroom: process.env.wroom_endpoint,
9
- PrismicAuthentication: process.env.authentication_server_endpoint,
10
- PrismicModels: process.env.customtypesapi_endpoint,
11
- PrismicUser: process.env.user_service_endpoint,
12
- AwsAclProvider: process.env.acl_provider_endpoint
9
+ PrismicWroom: addTrailingSlash.addTrailingSlash(process.env.wroom_endpoint),
10
+ PrismicAuthentication: addTrailingSlash.addTrailingSlash(process.env.authentication_server_endpoint),
11
+ PrismicModels: addTrailingSlash.addTrailingSlash(process.env.customtypesapi_endpoint),
12
+ PrismicUser: addTrailingSlash.addTrailingSlash(process.env.user_service_endpoint),
13
+ AwsAclProvider: addTrailingSlash.addTrailingSlash(process.env.acl_provider_endpoint)
13
14
  };
14
15
  const missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {
15
16
  return !apiEndpoints[key];
@@ -1 +1 @@
1
- {"version":3,"file":"API_ENDPOINTS.cjs","sources":["../../../src/constants/API_ENDPOINTS.ts"],"sourcesContent":["import { APPLICATION_MODE } from \"./APPLICATION_MODE\";\n\nexport type APIEndpoints = {\n\tPrismicWroom: string;\n\tPrismicAuthentication: string;\n\tPrismicModels: string;\n\tPrismicUser: string;\n\tAwsAclProvider: string;\n};\n\nexport const API_ENDPOINTS: APIEndpoints = (() => {\n\tswitch (process.env.SM_ENV) {\n\t\tcase APPLICATION_MODE.Development: {\n\t\t\tconst apiEndpoints = {\n\t\t\t\tPrismicWroom: process.env.wroom_endpoint,\n\t\t\t\tPrismicAuthentication: process.env.authentication_server_endpoint,\n\t\t\t\tPrismicModels: process.env.customtypesapi_endpoint,\n\t\t\t\tPrismicUser: process.env.user_service_endpoint,\n\t\t\t\tAwsAclProvider: process.env.acl_provider_endpoint,\n\t\t\t};\n\n\t\t\tconst missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {\n\t\t\t\treturn !apiEndpoints[key as keyof typeof apiEndpoints];\n\t\t\t});\n\n\t\t\tif (missingAPIEndpoints.length > 0) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`You are running Slice Machine in development mode where API endpoints are configured via environment variables. The following endpoints were not configured: ${missingAPIEndpoints.join(\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)}. Configure them before continuing.`,\n\t\t\t\t);\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\treturn apiEndpoints as APIEndpoints;\n\t\t}\n\n\t\tcase APPLICATION_MODE.Staging: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://wroom.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.wroom.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.wroom.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.wroom.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://2iamcvnxf4.execute-api.us-east-1.amazonaws.com/stage/\",\n\t\t\t};\n\t\t}\n\n\t\tcase APPLICATION_MODE.Production:\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://prismic.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.prismic.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.prismic.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.internal-prismic.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/\",\n\t\t\t};\n\t\t}\n\t}\n})();\n"],"names":["APPLICATION_MODE"],"mappings":";;;AAUO,MAAM,iBAA+B,MAAK;AACxC,UAAA,QAAQ,IAAI,QAAQ;AAAA,IAC3B,KAAKA,iBAAAA,iBAAiB,aAAa;AAClC,YAAM,eAAe;AAAA,QACpB,cAAc,QAAQ,IAAI;AAAA,QAC1B,uBAAuB,QAAQ,IAAI;AAAA,QACnC,eAAe,QAAQ,IAAI;AAAA,QAC3B,aAAa,QAAQ,IAAI;AAAA,QACzB,gBAAgB,QAAQ,IAAI;AAAA,MAAA;AAG7B,YAAM,sBAAsB,OAAO,KAAK,YAAY,EAAE,OAAO,CAAC,QAAO;AAC7D,eAAA,CAAC,aAAa,GAAgC;AAAA,MAAA,CACrD;AAEG,UAAA,oBAAoB,SAAS,GAAG;AACnC,gBAAQ,MACP,gKAAgK,oBAAoB,KACnL,IAAI,sCACiC;AAGvC,gBAAQ,KAAK,CAAC;AAAA,MACd;AAEM,aAAA;AAAA,IACP;AAAA,IAED,KAAKA,iBAAAA,iBAAiB,SAAS;AACvB,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAKA,iBAAAA,iBAAiB;AAAA,IACtB,SAAS;AACD,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACF;;"}
1
+ {"version":3,"file":"API_ENDPOINTS.cjs","sources":["../../../src/constants/API_ENDPOINTS.ts"],"sourcesContent":["import { addTrailingSlash } from \"../lib/addTrailingSlash\";\nimport { APPLICATION_MODE } from \"./APPLICATION_MODE\";\n\nexport type APIEndpoints = {\n\tPrismicWroom: string;\n\tPrismicAuthentication: string;\n\tPrismicModels: string;\n\tPrismicUser: string;\n\tAwsAclProvider: string;\n};\n\nexport const API_ENDPOINTS: APIEndpoints = (() => {\n\tswitch (process.env.SM_ENV) {\n\t\tcase APPLICATION_MODE.Development: {\n\t\t\tconst apiEndpoints = {\n\t\t\t\tPrismicWroom: addTrailingSlash(process.env.wroom_endpoint),\n\t\t\t\tPrismicAuthentication: addTrailingSlash(\n\t\t\t\t\tprocess.env.authentication_server_endpoint,\n\t\t\t\t),\n\t\t\t\tPrismicModels: addTrailingSlash(process.env.customtypesapi_endpoint),\n\t\t\t\tPrismicUser: addTrailingSlash(process.env.user_service_endpoint),\n\t\t\t\tAwsAclProvider: addTrailingSlash(process.env.acl_provider_endpoint),\n\t\t\t};\n\n\t\t\tconst missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {\n\t\t\t\treturn !apiEndpoints[key as keyof typeof apiEndpoints];\n\t\t\t});\n\n\t\t\tif (missingAPIEndpoints.length > 0) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`You are running Slice Machine in development mode where API endpoints are configured via environment variables. The following endpoints were not configured: ${missingAPIEndpoints.join(\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)}. Configure them before continuing.`,\n\t\t\t\t);\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\treturn apiEndpoints as APIEndpoints;\n\t\t}\n\n\t\tcase APPLICATION_MODE.Staging: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://wroom.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.wroom.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.wroom.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.wroom.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://2iamcvnxf4.execute-api.us-east-1.amazonaws.com/stage/\",\n\t\t\t};\n\t\t}\n\n\t\tcase APPLICATION_MODE.Production:\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://prismic.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.prismic.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.prismic.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.internal-prismic.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/\",\n\t\t\t};\n\t\t}\n\t}\n})();\n"],"names":["APPLICATION_MODE","addTrailingSlash"],"mappings":";;;;AAWO,MAAM,iBAA+B,MAAK;AACxC,UAAA,QAAQ,IAAI,QAAQ;AAAA,IAC3B,KAAKA,iBAAAA,iBAAiB,aAAa;AAClC,YAAM,eAAe;AAAA,QACpB,cAAcC,iBAAA,iBAAiB,QAAQ,IAAI,cAAc;AAAA,QACzD,uBAAuBA,iBAAA,iBACtB,QAAQ,IAAI,8BAA8B;AAAA,QAE3C,eAAeA,iBAAA,iBAAiB,QAAQ,IAAI,uBAAuB;AAAA,QACnE,aAAaA,iBAAA,iBAAiB,QAAQ,IAAI,qBAAqB;AAAA,QAC/D,gBAAgBA,iBAAA,iBAAiB,QAAQ,IAAI,qBAAqB;AAAA,MAAA;AAGnE,YAAM,sBAAsB,OAAO,KAAK,YAAY,EAAE,OAAO,CAAC,QAAO;AAC7D,eAAA,CAAC,aAAa,GAAgC;AAAA,MAAA,CACrD;AAEG,UAAA,oBAAoB,SAAS,GAAG;AACnC,gBAAQ,MACP,gKAAgK,oBAAoB,KACnL,IAAI,sCACiC;AAGvC,gBAAQ,KAAK,CAAC;AAAA,MACd;AAEM,aAAA;AAAA,IACP;AAAA,IAED,KAAKD,iBAAAA,iBAAiB,SAAS;AACvB,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAKA,iBAAAA,iBAAiB;AAAA,IACtB,SAAS;AACD,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACF;;"}
@@ -1,13 +1,14 @@
1
+ import { addTrailingSlash } from "../lib/addTrailingSlash.js";
1
2
  import { APPLICATION_MODE } from "./APPLICATION_MODE.js";
2
3
  const API_ENDPOINTS = (() => {
3
4
  switch (process.env.SM_ENV) {
4
5
  case APPLICATION_MODE.Development: {
5
6
  const apiEndpoints = {
6
- PrismicWroom: process.env.wroom_endpoint,
7
- PrismicAuthentication: process.env.authentication_server_endpoint,
8
- PrismicModels: process.env.customtypesapi_endpoint,
9
- PrismicUser: process.env.user_service_endpoint,
10
- AwsAclProvider: process.env.acl_provider_endpoint
7
+ PrismicWroom: addTrailingSlash(process.env.wroom_endpoint),
8
+ PrismicAuthentication: addTrailingSlash(process.env.authentication_server_endpoint),
9
+ PrismicModels: addTrailingSlash(process.env.customtypesapi_endpoint),
10
+ PrismicUser: addTrailingSlash(process.env.user_service_endpoint),
11
+ AwsAclProvider: addTrailingSlash(process.env.acl_provider_endpoint)
11
12
  };
12
13
  const missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {
13
14
  return !apiEndpoints[key];
@@ -1 +1 @@
1
- {"version":3,"file":"API_ENDPOINTS.js","sources":["../../../src/constants/API_ENDPOINTS.ts"],"sourcesContent":["import { APPLICATION_MODE } from \"./APPLICATION_MODE\";\n\nexport type APIEndpoints = {\n\tPrismicWroom: string;\n\tPrismicAuthentication: string;\n\tPrismicModels: string;\n\tPrismicUser: string;\n\tAwsAclProvider: string;\n};\n\nexport const API_ENDPOINTS: APIEndpoints = (() => {\n\tswitch (process.env.SM_ENV) {\n\t\tcase APPLICATION_MODE.Development: {\n\t\t\tconst apiEndpoints = {\n\t\t\t\tPrismicWroom: process.env.wroom_endpoint,\n\t\t\t\tPrismicAuthentication: process.env.authentication_server_endpoint,\n\t\t\t\tPrismicModels: process.env.customtypesapi_endpoint,\n\t\t\t\tPrismicUser: process.env.user_service_endpoint,\n\t\t\t\tAwsAclProvider: process.env.acl_provider_endpoint,\n\t\t\t};\n\n\t\t\tconst missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {\n\t\t\t\treturn !apiEndpoints[key as keyof typeof apiEndpoints];\n\t\t\t});\n\n\t\t\tif (missingAPIEndpoints.length > 0) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`You are running Slice Machine in development mode where API endpoints are configured via environment variables. The following endpoints were not configured: ${missingAPIEndpoints.join(\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)}. Configure them before continuing.`,\n\t\t\t\t);\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\treturn apiEndpoints as APIEndpoints;\n\t\t}\n\n\t\tcase APPLICATION_MODE.Staging: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://wroom.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.wroom.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.wroom.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.wroom.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://2iamcvnxf4.execute-api.us-east-1.amazonaws.com/stage/\",\n\t\t\t};\n\t\t}\n\n\t\tcase APPLICATION_MODE.Production:\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://prismic.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.prismic.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.prismic.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.internal-prismic.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/\",\n\t\t\t};\n\t\t}\n\t}\n})();\n"],"names":[],"mappings":";AAUO,MAAM,iBAA+B,MAAK;AACxC,UAAA,QAAQ,IAAI,QAAQ;AAAA,IAC3B,KAAK,iBAAiB,aAAa;AAClC,YAAM,eAAe;AAAA,QACpB,cAAc,QAAQ,IAAI;AAAA,QAC1B,uBAAuB,QAAQ,IAAI;AAAA,QACnC,eAAe,QAAQ,IAAI;AAAA,QAC3B,aAAa,QAAQ,IAAI;AAAA,QACzB,gBAAgB,QAAQ,IAAI;AAAA,MAAA;AAG7B,YAAM,sBAAsB,OAAO,KAAK,YAAY,EAAE,OAAO,CAAC,QAAO;AAC7D,eAAA,CAAC,aAAa,GAAgC;AAAA,MAAA,CACrD;AAEG,UAAA,oBAAoB,SAAS,GAAG;AACnC,gBAAQ,MACP,gKAAgK,oBAAoB,KACnL,IAAI,sCACiC;AAGvC,gBAAQ,KAAK,CAAC;AAAA,MACd;AAEM,aAAA;AAAA,IACP;AAAA,IAED,KAAK,iBAAiB,SAAS;AACvB,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,iBAAiB;AAAA,IACtB,SAAS;AACD,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACF;"}
1
+ {"version":3,"file":"API_ENDPOINTS.js","sources":["../../../src/constants/API_ENDPOINTS.ts"],"sourcesContent":["import { addTrailingSlash } from \"../lib/addTrailingSlash\";\nimport { APPLICATION_MODE } from \"./APPLICATION_MODE\";\n\nexport type APIEndpoints = {\n\tPrismicWroom: string;\n\tPrismicAuthentication: string;\n\tPrismicModels: string;\n\tPrismicUser: string;\n\tAwsAclProvider: string;\n};\n\nexport const API_ENDPOINTS: APIEndpoints = (() => {\n\tswitch (process.env.SM_ENV) {\n\t\tcase APPLICATION_MODE.Development: {\n\t\t\tconst apiEndpoints = {\n\t\t\t\tPrismicWroom: addTrailingSlash(process.env.wroom_endpoint),\n\t\t\t\tPrismicAuthentication: addTrailingSlash(\n\t\t\t\t\tprocess.env.authentication_server_endpoint,\n\t\t\t\t),\n\t\t\t\tPrismicModels: addTrailingSlash(process.env.customtypesapi_endpoint),\n\t\t\t\tPrismicUser: addTrailingSlash(process.env.user_service_endpoint),\n\t\t\t\tAwsAclProvider: addTrailingSlash(process.env.acl_provider_endpoint),\n\t\t\t};\n\n\t\t\tconst missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {\n\t\t\t\treturn !apiEndpoints[key as keyof typeof apiEndpoints];\n\t\t\t});\n\n\t\t\tif (missingAPIEndpoints.length > 0) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`You are running Slice Machine in development mode where API endpoints are configured via environment variables. The following endpoints were not configured: ${missingAPIEndpoints.join(\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)}. Configure them before continuing.`,\n\t\t\t\t);\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\treturn apiEndpoints as APIEndpoints;\n\t\t}\n\n\t\tcase APPLICATION_MODE.Staging: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://wroom.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.wroom.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.wroom.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.wroom.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://2iamcvnxf4.execute-api.us-east-1.amazonaws.com/stage/\",\n\t\t\t};\n\t\t}\n\n\t\tcase APPLICATION_MODE.Production:\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tPrismicWroom: \"https://prismic.io/\",\n\t\t\t\tPrismicAuthentication: \"https://auth.prismic.io/\",\n\t\t\t\tPrismicModels: \"https://customtypes.prismic.io/customtypes/\",\n\t\t\t\tPrismicUser: \"https://user.internal-prismic.io/\",\n\t\t\t\tAwsAclProvider:\n\t\t\t\t\t\"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/\",\n\t\t\t};\n\t\t}\n\t}\n})();\n"],"names":[],"mappings":";;AAWO,MAAM,iBAA+B,MAAK;AACxC,UAAA,QAAQ,IAAI,QAAQ;AAAA,IAC3B,KAAK,iBAAiB,aAAa;AAClC,YAAM,eAAe;AAAA,QACpB,cAAc,iBAAiB,QAAQ,IAAI,cAAc;AAAA,QACzD,uBAAuB,iBACtB,QAAQ,IAAI,8BAA8B;AAAA,QAE3C,eAAe,iBAAiB,QAAQ,IAAI,uBAAuB;AAAA,QACnE,aAAa,iBAAiB,QAAQ,IAAI,qBAAqB;AAAA,QAC/D,gBAAgB,iBAAiB,QAAQ,IAAI,qBAAqB;AAAA,MAAA;AAGnE,YAAM,sBAAsB,OAAO,KAAK,YAAY,EAAE,OAAO,CAAC,QAAO;AAC7D,eAAA,CAAC,aAAa,GAAgC;AAAA,MAAA,CACrD;AAEG,UAAA,oBAAoB,SAAS,GAAG;AACnC,gBAAQ,MACP,gKAAgK,oBAAoB,KACnL,IAAI,sCACiC;AAGvC,gBAAQ,KAAK,CAAC;AAAA,MACd;AAEM,aAAA;AAAA,IACP;AAAA,IAED,KAAK,iBAAiB,SAAS;AACvB,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,iBAAiB;AAAA,IACtB,SAAS;AACD,aAAA;AAAA,QACN,cAAc;AAAA,QACd,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,aAAa;AAAA,QACb,gBACC;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACF;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const addTrailingSlash = (url) => {
4
+ return url == null ? void 0 : url.replace(/\/?$/, "/");
5
+ };
6
+ exports.addTrailingSlash = addTrailingSlash;
7
+ //# sourceMappingURL=addTrailingSlash.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTrailingSlash.cjs","sources":["../../../src/lib/addTrailingSlash.ts"],"sourcesContent":["export const addTrailingSlash = (\n\turl: string | undefined,\n): string | undefined => {\n\treturn url?.replace(/\\/?$/, \"/\");\n};\n"],"names":[],"mappings":";;AAAa,MAAA,mBAAmB,CAC/B,QACuB;AAChB,SAAA,2BAAK,QAAQ,QAAQ;AAC7B;;"}
@@ -0,0 +1 @@
1
+ export declare const addTrailingSlash: (url: string | undefined) => string | undefined;
@@ -0,0 +1,7 @@
1
+ const addTrailingSlash = (url) => {
2
+ return url == null ? void 0 : url.replace(/\/?$/, "/");
3
+ };
4
+ export {
5
+ addTrailingSlash
6
+ };
7
+ //# sourceMappingURL=addTrailingSlash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTrailingSlash.js","sources":["../../../src/lib/addTrailingSlash.ts"],"sourcesContent":["export const addTrailingSlash = (\n\turl: string | undefined,\n): string | undefined => {\n\treturn url?.replace(/\\/?$/, \"/\");\n};\n"],"names":[],"mappings":"AAAa,MAAA,mBAAmB,CAC/B,QACuB;AAChB,SAAA,2BAAK,QAAQ,QAAQ;AAC7B;"}
@@ -117,7 +117,6 @@ class SliceMachineManager {
117
117
  apiEndpoint: sliceMachineConfig.apiEndpoint || buildPrismicRepositoryAPIEndpoint.buildPrismicRepositoryAPIEndpoint(sliceMachineConfig.repositoryName),
118
118
  localSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL
119
119
  },
120
- mockConfig: {},
121
120
  packageManager,
122
121
  repo: sliceMachineConfig.repositoryName,
123
122
  intercomHash: profile == null ? void 0 : profile.intercomHash,
@@ -177,9 +176,7 @@ class SliceMachineManager {
177
176
  extension: "extension",
178
177
  model,
179
178
  screenshots,
180
- mock: mocks,
181
- mockConfig: {}
182
- // TODO: This property can probably be removed.
179
+ mock: mocks
183
180
  });
184
181
  }
185
182
  }));
@@ -198,7 +195,12 @@ class SliceMachineManager {
198
195
  }
199
196
  }));
200
197
  }
201
- return libraries;
198
+ return libraries.sort((library1, library2) => {
199
+ var _a, _b;
200
+ const libraryIndex1 = ((_a = sliceMachineConfig.libraries) == null ? void 0 : _a.indexOf(library1.name)) || 0;
201
+ const libraryIndex2 = ((_b = sliceMachineConfig.libraries) == null ? void 0 : _b.indexOf(library2.name)) || 0;
202
+ return Math.sign(libraryIndex1 - libraryIndex2);
203
+ });
202
204
  }
203
205
  async _getCustomTypes() {
204
206
  const customTypes = [];
@@ -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\tmockConfig: unknown; // TODO: Remove\n\t\tframework: unknown; // TODO: Remove\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\tpath: string;\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\tmockConfig: unknown; // TODO: Remove\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\tframework: \"\",\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\tmockConfig: {},\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\tpath: \"__stub__\",\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\tmockConfig: {}, // TODO: This property can probably be removed.\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\treturn libraries;\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":";;;;;;;;;;;;;;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A,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;AAEM,WAAA;AAAA,EACR;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\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\tframework: unknown; // TODO: Remove\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\tpath: string;\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\tframework: \"\",\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\tpath: \"__stub__\",\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":";;;;;;;;;;;;;;;;;;;;;;;MA6Fa,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;AAC3B,SAAA,oBAAoB,IAAIC,yBAAA,yBAAyB,IAAI;AAErD,SAAA,UAAU,IAAIC,eAAA,eAAe,MAAM;AAAA,MACvC,eAAe,6BAAM;AAAA,IAAA,CACrB;AAEI,SAAA,UAAU,IAAIC,eAAA,eAAe,IAAI;AACjC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,SAAS,IAAIC,cAAA,cAAc,IAAI;AAC/B,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AACnC,SAAA,cAAc,IAAIC,mBAAA,mBAAmB,IAAI;AACzC,SAAA,YAAY,IAAIC,iBAAA,iBAAiB,IAAI;AAErC,SAAA,WAAW,IAAIC,gBAAA,gBAAgB,IAAI;AAEnC,SAAA,YAAY,IAAI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AA,EACR;AACA;;"}
@@ -27,7 +27,6 @@ type SliceMachineManagerGetStateReturnType = {
27
27
  repo: string;
28
28
  changelog?: PackageChangelog;
29
29
  packageManager: PackageManager;
30
- mockConfig: unknown;
31
30
  framework: unknown;
32
31
  };
33
32
  libraries: {
@@ -47,7 +46,6 @@ type SliceMachineManagerGetStateReturnType = {
47
46
  data: Buffer;
48
47
  }>;
49
48
  mock?: SharedSliceContent[];
50
- mockConfig: unknown;
51
49
  }[];
52
50
  meta: {
53
51
  name?: string;
@@ -115,7 +115,6 @@ class SliceMachineManager {
115
115
  apiEndpoint: sliceMachineConfig.apiEndpoint || buildPrismicRepositoryAPIEndpoint(sliceMachineConfig.repositoryName),
116
116
  localSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL
117
117
  },
118
- mockConfig: {},
119
118
  packageManager,
120
119
  repo: sliceMachineConfig.repositoryName,
121
120
  intercomHash: profile == null ? void 0 : profile.intercomHash,
@@ -175,9 +174,7 @@ class SliceMachineManager {
175
174
  extension: "extension",
176
175
  model,
177
176
  screenshots,
178
- mock: mocks,
179
- mockConfig: {}
180
- // TODO: This property can probably be removed.
177
+ mock: mocks
181
178
  });
182
179
  }
183
180
  }));
@@ -196,7 +193,12 @@ class SliceMachineManager {
196
193
  }
197
194
  }));
198
195
  }
199
- return libraries;
196
+ return libraries.sort((library1, library2) => {
197
+ var _a, _b;
198
+ const libraryIndex1 = ((_a = sliceMachineConfig.libraries) == null ? void 0 : _a.indexOf(library1.name)) || 0;
199
+ const libraryIndex2 = ((_b = sliceMachineConfig.libraries) == null ? void 0 : _b.indexOf(library2.name)) || 0;
200
+ return Math.sign(libraryIndex1 - libraryIndex2);
201
+ });
200
202
  }
201
203
  async _getCustomTypes() {
202
204
  const customTypes = [];
@@ -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\tmockConfig: unknown; // TODO: Remove\n\t\tframework: unknown; // TODO: Remove\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\tpath: string;\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\tmockConfig: unknown; // TODO: Remove\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\tframework: \"\",\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\tmockConfig: {},\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\tpath: \"__stub__\",\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\tmockConfig: {}, // TODO: This property can probably be removed.\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\treturn libraries;\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":";;;;;;;;;;;;;;;;;;;;;MA+Fa,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;A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AAC;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\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\tframework: unknown; // TODO: Remove\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\tpath: string;\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\tframework: \"\",\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\tpath: \"__stub__\",\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":";;;;;;;;;;;;;;;;;;;;;MA6Fa,oBAAmB;AAAA,EAmB/B,YAAY,MAAyC;AAlB7C;AAEA;AAER;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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AA8B,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;"}
@@ -23,8 +23,9 @@ class TelemetryManager extends BaseManager.BaseManager {
23
23
  __publicField(this, "_segmentClient");
24
24
  __publicField(this, "_anonymousID");
25
25
  __publicField(this, "_userID");
26
+ __publicField(this, "_context");
26
27
  }
27
- async initTelemetry() {
28
+ async initTelemetry(args) {
28
29
  if (this._segmentClient) {
29
30
  return;
30
31
  }
@@ -37,6 +38,7 @@ class TelemetryManager extends BaseManager.BaseManager {
37
38
  }
38
39
  });
39
40
  this._anonymousID = crypto.randomUUID();
41
+ this._context = { app: { name: args.appName, version: args.appVersion } };
40
42
  }
41
43
  // TODO: Should `userId` be automatically populated by the logged in
42
44
  // user? We already have their info via UserRepository.
@@ -46,9 +48,11 @@ class TelemetryManager extends BaseManager.BaseManager {
46
48
  const payload = {
47
49
  event: types.HumanSegmentEventType[event],
48
50
  properties: {
51
+ nodeVersion: process.versions.node,
49
52
  repo: repository,
50
53
  ...properties
51
- }
54
+ },
55
+ context: { ...this._context }
52
56
  };
53
57
  if (this._userID) {
54
58
  payload.userId = this._userID;
@@ -74,18 +78,19 @@ class TelemetryManager extends BaseManager.BaseManager {
74
78
  // by the logged in user? We already have their info via
75
79
  // UserRepository.
76
80
  identify(args) {
81
+ const payload = {
82
+ userId: args.userID,
83
+ anonymousId: this._anonymousID,
84
+ integrations: {
85
+ Intercom: {
86
+ user_hash: args.intercomHash
87
+ }
88
+ },
89
+ context: { ...this._context }
90
+ };
91
+ this._userID = args.userID;
77
92
  return new Promise((resolve) => {
78
93
  assertTelemetryInitialized(this._segmentClient);
79
- const payload = {
80
- userId: args.userID,
81
- anonymousId: this._anonymousID,
82
- integrations: {
83
- Intercom: {
84
- user_hash: args.intercomHash
85
- }
86
- }
87
- };
88
- this._userID = args.userID;
89
94
  this._segmentClient.identify(payload, (maybeError) => {
90
95
  if (maybeError) {
91
96
  console.warn(`An error occurred during Segment identify`, maybeError);
@@ -94,6 +99,28 @@ class TelemetryManager extends BaseManager.BaseManager {
94
99
  });
95
100
  });
96
101
  }
102
+ group(args) {
103
+ const { repositoryName, ...traits } = args;
104
+ const payload = {
105
+ groupId: repositoryName,
106
+ traits,
107
+ context: { ...this._context }
108
+ };
109
+ if (this._userID) {
110
+ payload.userId = this._userID;
111
+ } else {
112
+ payload.anonymousId = this._anonymousID;
113
+ }
114
+ return new Promise((resolve) => {
115
+ assertTelemetryInitialized(this._segmentClient);
116
+ this._segmentClient.group(payload, (maybeError) => {
117
+ if (maybeError) {
118
+ console.warn(`An error occurred during Segment group`, maybeError);
119
+ }
120
+ resolve();
121
+ });
122
+ });
123
+ }
97
124
  async checkIsTelemetryEnabled() {
98
125
  let root;
99
126
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"TelemetryManager.cjs","sources":["../../../../src/managers/telemetry/TelemetryManager.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport SegmentClient from \"analytics-node\";\n\nimport { readPrismicrc } from \"../../lib/prismicrc\";\n\nimport { API_TOKENS } from \"../../constants/API_TOKENS\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tHumanSegmentEventType,\n\tHumanSegmentEventTypes,\n\tSegmentEvents,\n} from \"./types\";\n\ntype TelemetryManagerTrackArgs = SegmentEvents;\n\ntype TelemetryManagerIdentifyArgs = {\n\tuserID: string;\n\tintercomHash: string;\n};\n\nfunction assertTelemetryInitialized(\n\tsegmentClient: SegmentClient | undefined,\n): asserts segmentClient is NonNullable<typeof segmentClient> {\n\tif (segmentClient == undefined) {\n\t\tthrow new Error(\n\t\t\t\"Telemetry has not been initialized. Run `SliceMachineManager.telemetry.prototype.initTelemetry()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\nexport class TelemetryManager extends BaseManager {\n\tprivate _segmentClient: SegmentClient | undefined = undefined;\n\tprivate _anonymousID: string | undefined = undefined;\n\tprivate _userID: string | undefined = undefined;\n\n\tasync initTelemetry(): Promise<void> {\n\t\tif (this._segmentClient) {\n\t\t\t// Prevent subsequent initializations.\n\t\t\treturn;\n\t\t}\n\n\t\tthis._segmentClient = new SegmentClient(API_TOKENS.SegmentKey, {\n\t\t\t// Since it's a local app, we do not benefit from event batching the way a server would normally do, all tracking event will be awaited.\n\t\t\tflushAt: 1,\n\t\t\t// TODO: Verify that this actually does not send data to Segment when false.\n\t\t\tenable: await this.checkIsTelemetryEnabled(),\n\t\t\terrorHandler: () => {\n\t\t\t\t// noop - We don't care if the tracking event\n\t\t\t\t// failed. Some users or networks intentionally\n\t\t\t\t// block Segment, so we can't block the app if\n\t\t\t\t// a tracking event is unsuccessful.\n\t\t\t},\n\t\t});\n\t\tthis._anonymousID = randomUUID();\n\t}\n\n\t// TODO: Should `userId` be automatically populated by the logged in\n\t// user? We already have their info via UserRepository.\n\ttrack(args: TelemetryManagerTrackArgs): Promise<void> {\n\t\tconst { event, repository, ...properties } = args;\n\n\t\tconst payload: {\n\t\t\tevent: HumanSegmentEventTypes;\n\t\t\tuserId?: string;\n\t\t\tanonymousId?: string;\n\t\t\tproperties?: Record<string, unknown>;\n\t\t\tcontext?: {\n\t\t\t\tgroupId?: {\n\t\t\t\t\tRepository?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t} = {\n\t\t\tevent: HumanSegmentEventType[event],\n\t\t\tproperties: {\n\t\t\t\trepo: repository,\n\t\t\t\t...properties,\n\t\t\t},\n\t\t};\n\n\t\tif (this._userID) {\n\t\t\tpayload.userId = this._userID;\n\t\t} else {\n\t\t\tpayload.anonymousId = this._anonymousID;\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\tpayload.context ||= {};\n\t\t\tpayload.context.groupId ||= {};\n\t\t\tpayload.context.groupId.Repository = repository;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.track(\n\t\t\t\tpayload as Parameters<typeof this._segmentClient.track>[0],\n\t\t\t\t(maybeError?: Error) => {\n\t\t\t\t\tif (maybeError) {\n\t\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`An error occurred during Segment tracking`,\n\t\t\t\t\t\t\tmaybeError,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// TODO: Should `userID` and `intercomHash` be automatically populated\n\t// by the logged in user? We already have their info via\n\t// UserRepository.\n\tidentify(args: TelemetryManagerIdentifyArgs): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\tconst payload = {\n\t\t\t\tuserId: args.userID,\n\t\t\t\tanonymousId: this._anonymousID,\n\t\t\t\tintegrations: {\n\t\t\t\t\tIntercom: {\n\t\t\t\t\t\tuser_hash: args.intercomHash,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t\tthis._userID = args.userID;\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.identify(payload, (maybeError?: Error) => {\n\t\t\t\tif (maybeError) {\n\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\tconsole.warn(`An error occurred during Segment identify`, maybeError);\n\t\t\t\t}\n\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tasync checkIsTelemetryEnabled(): Promise<boolean> {\n\t\tlet root: string;\n\t\ttry {\n\t\t\troot = await this.project.getRoot();\n\t\t} catch {\n\t\t\troot = await this.project.suggestRoot();\n\t\t}\n\n\t\treturn readPrismicrc(root).telemetry !== false;\n\t}\n}\n"],"names":["BaseManager","API_TOKENS","randomUUID","HumanSegmentEventType","readPrismicrc"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAS,2BACR,eAAwC;AAExC,MAAI,iBAAiB,QAAW;AACzB,UAAA,IAAI,MACT,kIAAkI;AAAA,EAEnI;AACF;AAEM,MAAO,yBAAyBA,YAAAA,YAAW;AAAA,EAA3C;AAAA;AACG;AACA;AACA;AAAA;AAAA,EAER,MAAM,gBAAa;AAClB,QAAI,KAAK,gBAAgB;AAExB;AAAA,IACA;AAED,SAAK,iBAAiB,IAAI,cAAcC,WAAAA,WAAW,YAAY;AAAA;AAAA,MAE9D,SAAS;AAAA;AAAA,MAET,QAAQ,MAAM,KAAK,wBAAyB;AAAA,MAC5C,cAAc,MAAK;AAAA,MAKnB;AAAA,IAAA,CACA;AACD,SAAK,eAAeC,OAAAA;EACrB;AAAA;AAAA;AAAA,EAIA,MAAM,MAA+B;;AACpC,UAAM,EAAE,OAAO,YAAY,GAAG,eAAe;AAE7C,UAAM,UAUF;AAAA,MACH,OAAOC,4BAAsB,KAAK;AAAA,MAClC,YAAY;AAAA,QACX,MAAM;AAAA,QACN,GAAG;AAAA,MACH;AAAA,IAAA;AAGF,QAAI,KAAK,SAAS;AACjB,cAAQ,SAAS,KAAK;AAAA,IAAA,OAChB;AACN,cAAQ,cAAc,KAAK;AAAA,IAC3B;AAED,QAAI,KAAK,YAAY;AACpB,cAAQ,YAAR,QAAQ,UAAY;AACZ,oBAAA,SAAQ,YAAR,GAAQ,UAAY;AACpB,cAAA,QAAQ,QAAQ,aAAa;AAAA,IACrC;AAEM,WAAA,IAAI,QAAQ,CAAC,YAAW;AAC9B,iCAA2B,KAAK,cAAc;AAG9C,WAAK,eAAe,MACnB,SACA,CAAC,eAAsB;AACtB,YAAI,YAAY;AAEP,kBAAA,KACP,6CACA,UAAU;AAAA,QAEX;;OAGD;AAAA,IAAA,CAEF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,MAAkC;AACnC,WAAA,IAAI,QAAQ,CAAC,YAAW;AAC9B,iCAA2B,KAAK,cAAc;AAE9C,YAAM,UAAU;AAAA,QACf,QAAQ,KAAK;AAAA,QACb,aAAa,KAAK;AAAA,QAClB,cAAc;AAAA,UACb,UAAU;AAAA,YACT,WAAW,KAAK;AAAA,UAChB;AAAA,QACD;AAAA,MAAA;AAEF,WAAK,UAAU,KAAK;AAGpB,WAAK,eAAe,SAAS,SAAS,CAAC,eAAsB;AAC5D,YAAI,YAAY;AAEP,kBAAA,KAAK,6CAA6C,UAAU;AAAA,QACpE;;OAGD;AAAA,IAAA,CACD;AAAA,EACF;AAAA,EAEA,MAAM,0BAAuB;AACxB,QAAA;AACA,QAAA;AACI,aAAA,MAAM,KAAK,QAAQ;YACzB;AACM,aAAA,MAAM,KAAK,QAAQ;IAC1B;AAEM,WAAAC,wBAAc,IAAI,EAAE,cAAc;AAAA,EAC1C;AACA;;"}
1
+ {"version":3,"file":"TelemetryManager.cjs","sources":["../../../../src/managers/telemetry/TelemetryManager.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport SegmentClient from \"analytics-node\";\n\nimport { readPrismicrc } from \"../../lib/prismicrc\";\n\nimport { API_TOKENS } from \"../../constants/API_TOKENS\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tHumanSegmentEventType,\n\tHumanSegmentEventTypes,\n\tSegmentEvents,\n} from \"./types\";\n\ntype TelemetryManagerInitTelemetryArgs = {\n\tappName: string;\n\tappVersion: string;\n};\n\ntype TelemetryManagerTrackArgs = SegmentEvents;\n\ntype TelemetryManagerIdentifyArgs = {\n\tuserID: string;\n\tintercomHash: string;\n};\n\ntype TelemetryManagerGroupArgs = {\n\trepositoryName: string;\n\tmanualLibsCount: number;\n\tdownloadedLibsCount: number;\n\tnpmLibsCount: number;\n\tdownloadedLibs: string[];\n};\n\ntype TelemetryManagerContext = {\n\tapp: {\n\t\tname: string;\n\t\tversion: string;\n\t};\n};\n\nfunction assertTelemetryInitialized(\n\tsegmentClient: SegmentClient | undefined,\n): asserts segmentClient is NonNullable<typeof segmentClient> {\n\tif (segmentClient == undefined) {\n\t\tthrow new Error(\n\t\t\t\"Telemetry has not been initialized. Run `SliceMachineManager.telemetry.prototype.initTelemetry()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\nexport class TelemetryManager extends BaseManager {\n\tprivate _segmentClient: SegmentClient | undefined = undefined;\n\tprivate _anonymousID: string | undefined = undefined;\n\tprivate _userID: string | undefined = undefined;\n\tprivate _context: TelemetryManagerContext | undefined = undefined;\n\n\tasync initTelemetry(args: TelemetryManagerInitTelemetryArgs): Promise<void> {\n\t\tif (this._segmentClient) {\n\t\t\t// Prevent subsequent initializations.\n\t\t\treturn;\n\t\t}\n\n\t\tthis._segmentClient = new SegmentClient(API_TOKENS.SegmentKey, {\n\t\t\t// Since it's a local app, we do not benefit from event batching the way a server would normally do, all tracking event will be awaited.\n\t\t\tflushAt: 1,\n\t\t\t// TODO: Verify that this actually does not send data to Segment when false.\n\t\t\tenable: await this.checkIsTelemetryEnabled(),\n\t\t\terrorHandler: () => {\n\t\t\t\t// noop - We don't care if the tracking event\n\t\t\t\t// failed. Some users or networks intentionally\n\t\t\t\t// block Segment, so we can't block the app if\n\t\t\t\t// a tracking event is unsuccessful.\n\t\t\t},\n\t\t});\n\t\tthis._anonymousID = randomUUID();\n\t\tthis._context = { app: { name: args.appName, version: args.appVersion } };\n\t}\n\n\t// TODO: Should `userId` be automatically populated by the logged in\n\t// user? We already have their info via UserRepository.\n\ttrack(args: TelemetryManagerTrackArgs): Promise<void> {\n\t\tconst { event, repository, ...properties } = args;\n\n\t\tconst payload: {\n\t\t\tevent: HumanSegmentEventTypes;\n\t\t\tuserId?: string;\n\t\t\tanonymousId?: string;\n\t\t\tproperties?: Record<string, unknown>;\n\t\t\tcontext?: Partial<TelemetryManagerContext> & {\n\t\t\t\tgroupId?: {\n\t\t\t\t\tRepository?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t} = {\n\t\t\tevent: HumanSegmentEventType[event],\n\t\t\tproperties: {\n\t\t\t\tnodeVersion: process.versions.node,\n\t\t\t\trepo: repository,\n\t\t\t\t...properties,\n\t\t\t},\n\t\t\tcontext: { ...this._context },\n\t\t};\n\n\t\tif (this._userID) {\n\t\t\tpayload.userId = this._userID;\n\t\t} else {\n\t\t\tpayload.anonymousId = this._anonymousID;\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\tpayload.context ||= {};\n\t\t\tpayload.context.groupId ||= {};\n\t\t\tpayload.context.groupId.Repository = repository;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.track(\n\t\t\t\tpayload as Parameters<typeof this._segmentClient.track>[0],\n\t\t\t\t(maybeError?: Error) => {\n\t\t\t\t\tif (maybeError) {\n\t\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`An error occurred during Segment tracking`,\n\t\t\t\t\t\t\tmaybeError,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// TODO: Should `userID` and `intercomHash` be automatically populated\n\t// by the logged in user? We already have their info via\n\t// UserRepository.\n\tidentify(args: TelemetryManagerIdentifyArgs): Promise<void> {\n\t\tconst payload = {\n\t\t\tuserId: args.userID,\n\t\t\tanonymousId: this._anonymousID,\n\t\t\tintegrations: {\n\t\t\t\tIntercom: {\n\t\t\t\t\tuser_hash: args.intercomHash,\n\t\t\t\t},\n\t\t\t},\n\t\t\tcontext: { ...this._context },\n\t\t};\n\n\t\tthis._userID = args.userID;\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.identify(payload, (maybeError?: Error) => {\n\t\t\t\tif (maybeError) {\n\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\tconsole.warn(`An error occurred during Segment identify`, maybeError);\n\t\t\t\t}\n\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tgroup(args: TelemetryManagerGroupArgs): Promise<void> {\n\t\tconst { repositoryName, ...traits } = args;\n\n\t\tconst payload: {\n\t\t\tgroupId: string;\n\t\t\tuserId?: string;\n\t\t\tanonymousId?: string;\n\t\t\ttraits?: Record<string, unknown>;\n\t\t\tcontext?: Partial<TelemetryManagerContext>;\n\t\t} = {\n\t\t\tgroupId: repositoryName,\n\t\t\ttraits,\n\t\t\tcontext: { ...this._context },\n\t\t};\n\n\t\tif (this._userID) {\n\t\t\tpayload.userId = this._userID;\n\t\t} else {\n\t\t\tpayload.anonymousId = this._anonymousID;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\tthis._segmentClient.group(\n\t\t\t\tpayload as Parameters<typeof this._segmentClient.group>[0],\n\t\t\t\t(maybeError?: Error) => {\n\t\t\t\t\tif (maybeError) {\n\t\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\t\tconsole.warn(`An error occurred during Segment group`, maybeError);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tasync checkIsTelemetryEnabled(): Promise<boolean> {\n\t\tlet root: string;\n\t\ttry {\n\t\t\troot = await this.project.getRoot();\n\t\t} catch {\n\t\t\troot = await this.project.suggestRoot();\n\t\t}\n\n\t\treturn readPrismicrc(root).telemetry !== false;\n\t}\n}\n"],"names":["BaseManager","API_TOKENS","randomUUID","HumanSegmentEventType","readPrismicrc"],"mappings":";;;;;;;;;;;;;;AA2CA,SAAS,2BACR,eAAwC;AAExC,MAAI,iBAAiB,QAAW;AACzB,UAAA,IAAI,MACT,kIAAkI;AAAA,EAEnI;AACF;AAEM,MAAO,yBAAyBA,YAAAA,YAAW;AAAA,EAA3C;AAAA;AACG;AACA;AACA;AACA;AAAA;AAAA,EAER,MAAM,cAAc,MAAuC;AAC1D,QAAI,KAAK,gBAAgB;AAExB;AAAA,IACA;AAED,SAAK,iBAAiB,IAAI,cAAcC,WAAAA,WAAW,YAAY;AAAA;AAAA,MAE9D,SAAS;AAAA;AAAA,MAET,QAAQ,MAAM,KAAK,wBAAyB;AAAA,MAC5C,cAAc,MAAK;AAAA,MAKnB;AAAA,IAAA,CACA;AACD,SAAK,eAAeC,OAAAA;AACf,SAAA,WAAW,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,SAAS,KAAK;EAC5D;AAAA;AAAA;AAAA,EAIA,MAAM,MAA+B;;AACpC,UAAM,EAAE,OAAO,YAAY,GAAG,eAAe;AAE7C,UAAM,UAUF;AAAA,MACH,OAAOC,4BAAsB,KAAK;AAAA,MAClC,YAAY;AAAA,QACX,aAAa,QAAQ,SAAS;AAAA,QAC9B,MAAM;AAAA,QACN,GAAG;AAAA,MACH;AAAA,MACD,SAAS,EAAE,GAAG,KAAK,SAAU;AAAA,IAAA;AAG9B,QAAI,KAAK,SAAS;AACjB,cAAQ,SAAS,KAAK;AAAA,IAAA,OAChB;AACN,cAAQ,cAAc,KAAK;AAAA,IAC3B;AAED,QAAI,KAAK,YAAY;AACpB,cAAQ,YAAR,QAAQ,UAAY;AACZ,oBAAA,SAAQ,YAAR,GAAQ,UAAY;AACpB,cAAA,QAAQ,QAAQ,aAAa;AAAA,IACrC;AAEM,WAAA,IA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ACzB;AACM,aAAA,MAAM,KAAK,QAAQ;IAC1B;AAEM,WAAAC,wBAAc,IAAI,EAAE,cAAc;AAAA,EAC1C;AACA;;"}
@@ -1,17 +1,30 @@
1
1
  import { BaseManager } from "../BaseManager";
2
2
  import { SegmentEvents } from "./types";
3
+ type TelemetryManagerInitTelemetryArgs = {
4
+ appName: string;
5
+ appVersion: string;
6
+ };
3
7
  type TelemetryManagerTrackArgs = SegmentEvents;
4
8
  type TelemetryManagerIdentifyArgs = {
5
9
  userID: string;
6
10
  intercomHash: string;
7
11
  };
12
+ type TelemetryManagerGroupArgs = {
13
+ repositoryName: string;
14
+ manualLibsCount: number;
15
+ downloadedLibsCount: number;
16
+ npmLibsCount: number;
17
+ downloadedLibs: string[];
18
+ };
8
19
  export declare class TelemetryManager extends BaseManager {
9
20
  private _segmentClient;
10
21
  private _anonymousID;
11
22
  private _userID;
12
- initTelemetry(): Promise<void>;
23
+ private _context;
24
+ initTelemetry(args: TelemetryManagerInitTelemetryArgs): Promise<void>;
13
25
  track(args: TelemetryManagerTrackArgs): Promise<void>;
14
26
  identify(args: TelemetryManagerIdentifyArgs): Promise<void>;
27
+ group(args: TelemetryManagerGroupArgs): Promise<void>;
15
28
  checkIsTelemetryEnabled(): Promise<boolean>;
16
29
  }
17
30
  export {};
@@ -21,8 +21,9 @@ class TelemetryManager extends BaseManager {
21
21
  __publicField(this, "_segmentClient");
22
22
  __publicField(this, "_anonymousID");
23
23
  __publicField(this, "_userID");
24
+ __publicField(this, "_context");
24
25
  }
25
- async initTelemetry() {
26
+ async initTelemetry(args) {
26
27
  if (this._segmentClient) {
27
28
  return;
28
29
  }
@@ -35,6 +36,7 @@ class TelemetryManager extends BaseManager {
35
36
  }
36
37
  });
37
38
  this._anonymousID = randomUUID();
39
+ this._context = { app: { name: args.appName, version: args.appVersion } };
38
40
  }
39
41
  // TODO: Should `userId` be automatically populated by the logged in
40
42
  // user? We already have their info via UserRepository.
@@ -44,9 +46,11 @@ class TelemetryManager extends BaseManager {
44
46
  const payload = {
45
47
  event: HumanSegmentEventType[event],
46
48
  properties: {
49
+ nodeVersion: process.versions.node,
47
50
  repo: repository,
48
51
  ...properties
49
- }
52
+ },
53
+ context: { ...this._context }
50
54
  };
51
55
  if (this._userID) {
52
56
  payload.userId = this._userID;
@@ -72,18 +76,19 @@ class TelemetryManager extends BaseManager {
72
76
  // by the logged in user? We already have their info via
73
77
  // UserRepository.
74
78
  identify(args) {
79
+ const payload = {
80
+ userId: args.userID,
81
+ anonymousId: this._anonymousID,
82
+ integrations: {
83
+ Intercom: {
84
+ user_hash: args.intercomHash
85
+ }
86
+ },
87
+ context: { ...this._context }
88
+ };
89
+ this._userID = args.userID;
75
90
  return new Promise((resolve) => {
76
91
  assertTelemetryInitialized(this._segmentClient);
77
- const payload = {
78
- userId: args.userID,
79
- anonymousId: this._anonymousID,
80
- integrations: {
81
- Intercom: {
82
- user_hash: args.intercomHash
83
- }
84
- }
85
- };
86
- this._userID = args.userID;
87
92
  this._segmentClient.identify(payload, (maybeError) => {
88
93
  if (maybeError) {
89
94
  console.warn(`An error occurred during Segment identify`, maybeError);
@@ -92,6 +97,28 @@ class TelemetryManager extends BaseManager {
92
97
  });
93
98
  });
94
99
  }
100
+ group(args) {
101
+ const { repositoryName, ...traits } = args;
102
+ const payload = {
103
+ groupId: repositoryName,
104
+ traits,
105
+ context: { ...this._context }
106
+ };
107
+ if (this._userID) {
108
+ payload.userId = this._userID;
109
+ } else {
110
+ payload.anonymousId = this._anonymousID;
111
+ }
112
+ return new Promise((resolve) => {
113
+ assertTelemetryInitialized(this._segmentClient);
114
+ this._segmentClient.group(payload, (maybeError) => {
115
+ if (maybeError) {
116
+ console.warn(`An error occurred during Segment group`, maybeError);
117
+ }
118
+ resolve();
119
+ });
120
+ });
121
+ }
95
122
  async checkIsTelemetryEnabled() {
96
123
  let root;
97
124
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"TelemetryManager.js","sources":["../../../../src/managers/telemetry/TelemetryManager.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport SegmentClient from \"analytics-node\";\n\nimport { readPrismicrc } from \"../../lib/prismicrc\";\n\nimport { API_TOKENS } from \"../../constants/API_TOKENS\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tHumanSegmentEventType,\n\tHumanSegmentEventTypes,\n\tSegmentEvents,\n} from \"./types\";\n\ntype TelemetryManagerTrackArgs = SegmentEvents;\n\ntype TelemetryManagerIdentifyArgs = {\n\tuserID: string;\n\tintercomHash: string;\n};\n\nfunction assertTelemetryInitialized(\n\tsegmentClient: SegmentClient | undefined,\n): asserts segmentClient is NonNullable<typeof segmentClient> {\n\tif (segmentClient == undefined) {\n\t\tthrow new Error(\n\t\t\t\"Telemetry has not been initialized. Run `SliceMachineManager.telemetry.prototype.initTelemetry()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\nexport class TelemetryManager extends BaseManager {\n\tprivate _segmentClient: SegmentClient | undefined = undefined;\n\tprivate _anonymousID: string | undefined = undefined;\n\tprivate _userID: string | undefined = undefined;\n\n\tasync initTelemetry(): Promise<void> {\n\t\tif (this._segmentClient) {\n\t\t\t// Prevent subsequent initializations.\n\t\t\treturn;\n\t\t}\n\n\t\tthis._segmentClient = new SegmentClient(API_TOKENS.SegmentKey, {\n\t\t\t// Since it's a local app, we do not benefit from event batching the way a server would normally do, all tracking event will be awaited.\n\t\t\tflushAt: 1,\n\t\t\t// TODO: Verify that this actually does not send data to Segment when false.\n\t\t\tenable: await this.checkIsTelemetryEnabled(),\n\t\t\terrorHandler: () => {\n\t\t\t\t// noop - We don't care if the tracking event\n\t\t\t\t// failed. Some users or networks intentionally\n\t\t\t\t// block Segment, so we can't block the app if\n\t\t\t\t// a tracking event is unsuccessful.\n\t\t\t},\n\t\t});\n\t\tthis._anonymousID = randomUUID();\n\t}\n\n\t// TODO: Should `userId` be automatically populated by the logged in\n\t// user? We already have their info via UserRepository.\n\ttrack(args: TelemetryManagerTrackArgs): Promise<void> {\n\t\tconst { event, repository, ...properties } = args;\n\n\t\tconst payload: {\n\t\t\tevent: HumanSegmentEventTypes;\n\t\t\tuserId?: string;\n\t\t\tanonymousId?: string;\n\t\t\tproperties?: Record<string, unknown>;\n\t\t\tcontext?: {\n\t\t\t\tgroupId?: {\n\t\t\t\t\tRepository?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t} = {\n\t\t\tevent: HumanSegmentEventType[event],\n\t\t\tproperties: {\n\t\t\t\trepo: repository,\n\t\t\t\t...properties,\n\t\t\t},\n\t\t};\n\n\t\tif (this._userID) {\n\t\t\tpayload.userId = this._userID;\n\t\t} else {\n\t\t\tpayload.anonymousId = this._anonymousID;\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\tpayload.context ||= {};\n\t\t\tpayload.context.groupId ||= {};\n\t\t\tpayload.context.groupId.Repository = repository;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.track(\n\t\t\t\tpayload as Parameters<typeof this._segmentClient.track>[0],\n\t\t\t\t(maybeError?: Error) => {\n\t\t\t\t\tif (maybeError) {\n\t\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`An error occurred during Segment tracking`,\n\t\t\t\t\t\t\tmaybeError,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// TODO: Should `userID` and `intercomHash` be automatically populated\n\t// by the logged in user? We already have their info via\n\t// UserRepository.\n\tidentify(args: TelemetryManagerIdentifyArgs): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\tconst payload = {\n\t\t\t\tuserId: args.userID,\n\t\t\t\tanonymousId: this._anonymousID,\n\t\t\t\tintegrations: {\n\t\t\t\t\tIntercom: {\n\t\t\t\t\t\tuser_hash: args.intercomHash,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t\tthis._userID = args.userID;\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.identify(payload, (maybeError?: Error) => {\n\t\t\t\tif (maybeError) {\n\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\tconsole.warn(`An error occurred during Segment identify`, maybeError);\n\t\t\t\t}\n\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tasync checkIsTelemetryEnabled(): Promise<boolean> {\n\t\tlet root: string;\n\t\ttry {\n\t\t\troot = await this.project.getRoot();\n\t\t} catch {\n\t\t\troot = await this.project.suggestRoot();\n\t\t}\n\n\t\treturn readPrismicrc(root).telemetry !== false;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAuBA,SAAS,2BACR,eAAwC;AAExC,MAAI,iBAAiB,QAAW;AACzB,UAAA,IAAI,MACT,kIAAkI;AAAA,EAEnI;AACF;AAEM,MAAO,yBAAyB,YAAW;AAAA,EAA3C;AAAA;AACG;AACA;AACA;AAAA;AAAA,EAER,MAAM,gBAAa;AAClB,QAAI,KAAK,gBAAgB;AAExB;AAAA,IACA;AAED,SAAK,iBAAiB,IAAI,cAAc,WAAW,YAAY;AAAA;AAAA,MAE9D,SAAS;AAAA;AAAA,MAET,QAAQ,MAAM,KAAK,wBAAyB;AAAA,MAC5C,cAAc,MAAK;AAAA,MAKnB;AAAA,IAAA,CACA;AACD,SAAK,eAAe;EACrB;AAAA;AAAA;AAAA,EAIA,MAAM,MAA+B;;AACpC,UAAM,EAAE,OAAO,YAAY,GAAG,eAAe;AAE7C,UAAM,UAUF;AAAA,MACH,OAAO,sBAAsB,KAAK;AAAA,MAClC,YAAY;AAAA,QACX,MAAM;AAAA,QACN,GAAG;AAAA,MACH;AAAA,IAAA;AAGF,QAAI,KAAK,SAAS;AACjB,cAAQ,SAAS,KAAK;AAAA,IAAA,OAChB;AACN,cAAQ,cAAc,KAAK;AAAA,IAC3B;AAED,QAAI,KAAK,YAAY;AACpB,cAAQ,YAAR,QAAQ,UAAY;AACZ,oBAAA,SAAQ,YAAR,GAAQ,UAAY;AACpB,cAAA,QAAQ,QAAQ,aAAa;AAAA,IACrC;AAEM,WAAA,IAAI,QAAQ,CAAC,YAAW;AAC9B,iCAA2B,KAAK,cAAc;AAG9C,WAAK,eAAe,MACnB,SACA,CAAC,eAAsB;AACtB,YAAI,YAAY;AAEP,kBAAA,KACP,6CACA,UAAU;AAAA,QAEX;;OAGD;AAAA,IAAA,CAEF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,MAAkC;AACnC,WAAA,IAAI,QAAQ,CAAC,YAAW;AAC9B,iCAA2B,KAAK,cAAc;AAE9C,YAAM,UAAU;AAAA,QACf,QAAQ,KAAK;AAAA,QACb,aAAa,KAAK;AAAA,QAClB,cAAc;AAAA,UACb,UAAU;AAAA,YACT,WAAW,KAAK;AAAA,UAChB;AAAA,QACD;AAAA,MAAA;AAEF,WAAK,UAAU,KAAK;AAGpB,WAAK,eAAe,SAAS,SAAS,CAAC,eAAsB;AAC5D,YAAI,YAAY;AAEP,kBAAA,KAAK,6CAA6C,UAAU;AAAA,QACpE;;OAGD;AAAA,IAAA,CACD;AAAA,EACF;AAAA,EAEA,MAAM,0BAAuB;AACxB,QAAA;AACA,QAAA;AACI,aAAA,MAAM,KAAK,QAAQ;YACzB;AACM,aAAA,MAAM,KAAK,QAAQ;IAC1B;AAEM,WAAA,cAAc,IAAI,EAAE,cAAc;AAAA,EAC1C;AACA;"}
1
+ {"version":3,"file":"TelemetryManager.js","sources":["../../../../src/managers/telemetry/TelemetryManager.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport SegmentClient from \"analytics-node\";\n\nimport { readPrismicrc } from \"../../lib/prismicrc\";\n\nimport { API_TOKENS } from \"../../constants/API_TOKENS\";\n\nimport { BaseManager } from \"../BaseManager\";\n\nimport {\n\tHumanSegmentEventType,\n\tHumanSegmentEventTypes,\n\tSegmentEvents,\n} from \"./types\";\n\ntype TelemetryManagerInitTelemetryArgs = {\n\tappName: string;\n\tappVersion: string;\n};\n\ntype TelemetryManagerTrackArgs = SegmentEvents;\n\ntype TelemetryManagerIdentifyArgs = {\n\tuserID: string;\n\tintercomHash: string;\n};\n\ntype TelemetryManagerGroupArgs = {\n\trepositoryName: string;\n\tmanualLibsCount: number;\n\tdownloadedLibsCount: number;\n\tnpmLibsCount: number;\n\tdownloadedLibs: string[];\n};\n\ntype TelemetryManagerContext = {\n\tapp: {\n\t\tname: string;\n\t\tversion: string;\n\t};\n};\n\nfunction assertTelemetryInitialized(\n\tsegmentClient: SegmentClient | undefined,\n): asserts segmentClient is NonNullable<typeof segmentClient> {\n\tif (segmentClient == undefined) {\n\t\tthrow new Error(\n\t\t\t\"Telemetry has not been initialized. Run `SliceMachineManager.telemetry.prototype.initTelemetry()` before re-calling this method.\",\n\t\t);\n\t}\n}\n\nexport class TelemetryManager extends BaseManager {\n\tprivate _segmentClient: SegmentClient | undefined = undefined;\n\tprivate _anonymousID: string | undefined = undefined;\n\tprivate _userID: string | undefined = undefined;\n\tprivate _context: TelemetryManagerContext | undefined = undefined;\n\n\tasync initTelemetry(args: TelemetryManagerInitTelemetryArgs): Promise<void> {\n\t\tif (this._segmentClient) {\n\t\t\t// Prevent subsequent initializations.\n\t\t\treturn;\n\t\t}\n\n\t\tthis._segmentClient = new SegmentClient(API_TOKENS.SegmentKey, {\n\t\t\t// Since it's a local app, we do not benefit from event batching the way a server would normally do, all tracking event will be awaited.\n\t\t\tflushAt: 1,\n\t\t\t// TODO: Verify that this actually does not send data to Segment when false.\n\t\t\tenable: await this.checkIsTelemetryEnabled(),\n\t\t\terrorHandler: () => {\n\t\t\t\t// noop - We don't care if the tracking event\n\t\t\t\t// failed. Some users or networks intentionally\n\t\t\t\t// block Segment, so we can't block the app if\n\t\t\t\t// a tracking event is unsuccessful.\n\t\t\t},\n\t\t});\n\t\tthis._anonymousID = randomUUID();\n\t\tthis._context = { app: { name: args.appName, version: args.appVersion } };\n\t}\n\n\t// TODO: Should `userId` be automatically populated by the logged in\n\t// user? We already have their info via UserRepository.\n\ttrack(args: TelemetryManagerTrackArgs): Promise<void> {\n\t\tconst { event, repository, ...properties } = args;\n\n\t\tconst payload: {\n\t\t\tevent: HumanSegmentEventTypes;\n\t\t\tuserId?: string;\n\t\t\tanonymousId?: string;\n\t\t\tproperties?: Record<string, unknown>;\n\t\t\tcontext?: Partial<TelemetryManagerContext> & {\n\t\t\t\tgroupId?: {\n\t\t\t\t\tRepository?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t} = {\n\t\t\tevent: HumanSegmentEventType[event],\n\t\t\tproperties: {\n\t\t\t\tnodeVersion: process.versions.node,\n\t\t\t\trepo: repository,\n\t\t\t\t...properties,\n\t\t\t},\n\t\t\tcontext: { ...this._context },\n\t\t};\n\n\t\tif (this._userID) {\n\t\t\tpayload.userId = this._userID;\n\t\t} else {\n\t\t\tpayload.anonymousId = this._anonymousID;\n\t\t}\n\n\t\tif (args.repository) {\n\t\t\tpayload.context ||= {};\n\t\t\tpayload.context.groupId ||= {};\n\t\t\tpayload.context.groupId.Repository = repository;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.track(\n\t\t\t\tpayload as Parameters<typeof this._segmentClient.track>[0],\n\t\t\t\t(maybeError?: Error) => {\n\t\t\t\t\tif (maybeError) {\n\t\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`An error occurred during Segment tracking`,\n\t\t\t\t\t\t\tmaybeError,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t// TODO: Should `userID` and `intercomHash` be automatically populated\n\t// by the logged in user? We already have their info via\n\t// UserRepository.\n\tidentify(args: TelemetryManagerIdentifyArgs): Promise<void> {\n\t\tconst payload = {\n\t\t\tuserId: args.userID,\n\t\t\tanonymousId: this._anonymousID,\n\t\t\tintegrations: {\n\t\t\t\tIntercom: {\n\t\t\t\t\tuser_hash: args.intercomHash,\n\t\t\t\t},\n\t\t\t},\n\t\t\tcontext: { ...this._context },\n\t\t};\n\n\t\tthis._userID = args.userID;\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\t// TODO: Make sure client fails gracefully when no internet connection\n\t\t\tthis._segmentClient.identify(payload, (maybeError?: Error) => {\n\t\t\t\tif (maybeError) {\n\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\tconsole.warn(`An error occurred during Segment identify`, maybeError);\n\t\t\t\t}\n\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tgroup(args: TelemetryManagerGroupArgs): Promise<void> {\n\t\tconst { repositoryName, ...traits } = args;\n\n\t\tconst payload: {\n\t\t\tgroupId: string;\n\t\t\tuserId?: string;\n\t\t\tanonymousId?: string;\n\t\t\ttraits?: Record<string, unknown>;\n\t\t\tcontext?: Partial<TelemetryManagerContext>;\n\t\t} = {\n\t\t\tgroupId: repositoryName,\n\t\t\ttraits,\n\t\t\tcontext: { ...this._context },\n\t\t};\n\n\t\tif (this._userID) {\n\t\t\tpayload.userId = this._userID;\n\t\t} else {\n\t\t\tpayload.anonymousId = this._anonymousID;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tassertTelemetryInitialized(this._segmentClient);\n\n\t\t\tthis._segmentClient.group(\n\t\t\t\tpayload as Parameters<typeof this._segmentClient.group>[0],\n\t\t\t\t(maybeError?: Error) => {\n\t\t\t\t\tif (maybeError) {\n\t\t\t\t\t\t// TODO: Not sure how we want to deal with that\n\t\t\t\t\t\tconsole.warn(`An error occurred during Segment group`, maybeError);\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tasync checkIsTelemetryEnabled(): Promise<boolean> {\n\t\tlet root: string;\n\t\ttry {\n\t\t\troot = await this.project.getRoot();\n\t\t} catch {\n\t\t\troot = await this.project.suggestRoot();\n\t\t}\n\n\t\treturn readPrismicrc(root).telemetry !== false;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AA2CA,SAAS,2BACR,eAAwC;AAExC,MAAI,iBAAiB,QAAW;AACzB,UAAA,IAAI,MACT,kIAAkI;AAAA,EAEnI;AACF;AAEM,MAAO,yBAAyB,YAAW;AAAA,EAA3C;AAAA;AACG;AACA;AACA;AACA;AAAA;AAAA,EAER,MAAM,cAAc,MAAuC;AAC1D,QAAI,KAAK,gBAAgB;AAExB;AAAA,IACA;AAED,SAAK,iBAAiB,IAAI,cAAc,WAAW,YAAY;AAAA;AAAA,MAE9D,SAAS;AAAA;AAAA,MAET,QAAQ,MAAM,KAAK,wBAAyB;AAAA,MAC5C,cAAc,MAAK;AAAA,MAKnB;AAAA,IAAA,CACA;AACD,SAAK,eAAe;AACf,SAAA,WAAW,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,SAAS,KAAK;EAC5D;AAAA;AAAA;AAAA,EAIA,MAAM,MAA+B;;AACpC,UAAM,EAAE,OAAO,YAAY,GAAG,eAAe;AAE7C,UAAM,UAUF;AAAA,MACH,OAAO,sBAAsB,KAAK;AAAA,MAClC,YAAY;AAAA,QACX,aAAa,QAAQ,SAAS;AAAA,QAC9B,MAAM;AAAA,QACN,GAAG;AAAA,MACH;AAAA,MACD,SAAS,EAAE,GAAG,KAAK,SAAU;AAAA,IAAA;AAG9B,QAAI,KAAK,SAAS;AACjB,cAAQ,SAAS,KAAK;AAAA,IAAA,OAChB;AACN,cAAQ,cAAc,KAAK;AAAA,IAC3B;AAED,QAAI,KAAK,YAAY;AAC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AAAA,QACjE;;OAGD;AAAA,IAAA,CAEF;AAAA,EACF;AAAA,EAEA,MAAM,0BAAuB;AACxB,QAAA;AACA,QAAA;AACI,aAAA,MAAM,KAAK,QAAQ;YACzB;AACM,aAAA,MAAM,KAAK,QAAQ;IAC1B;AAEM,WAAA,cAAc,IAAI,EAAE,cAAc;AAAA,EAC1C;AACA;"}
@@ -21,8 +21,6 @@ const SegmentEventType = {
21
21
  customType_sliceZoneUpdated: "custom-type:slice-zone-updated",
22
22
  customType_saved: "custom-type:saved",
23
23
  slice_created: "slice:created",
24
- identifyUser: "identify-user",
25
- groupLibraries: "group-libraries",
26
24
  screenshotTaken: "screenshot-taken",
27
25
  changes_pushed: "changes:pushed",
28
26
  changes_limitReach: "changes:limit-reach",
@@ -49,8 +47,6 @@ const HumanSegmentEventType = {
49
47
  [SegmentEventType.customType_sliceZoneUpdated]: "SliceMachine Slicezone Updated",
50
48
  [SegmentEventType.customType_saved]: "SliceMachine Custom Type Saved",
51
49
  [SegmentEventType.slice_created]: "SliceMachine Slice Created",
52
- [SegmentEventType.identifyUser]: "IdentifyUser",
53
- [SegmentEventType.groupLibraries]: "GroupLibraries",
54
50
  [SegmentEventType.screenshotTaken]: "SliceMachine Screenshot Taken",
55
51
  [SegmentEventType.changes_pushed]: "SliceMachine Changes Pushed",
56
52
  [SegmentEventType.changes_limitReach]: "SliceMachine Changes Limit Reach",
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import 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\tonboarding_start: \"onboarding:start\",\n\tonboarding_skip: \"onboarding:skip\",\n\tonboarding_continue_screenIntro: \"onboarding:continue:screen-intro\",\n\tonboarding_continue_screen1: \"onboarding:continue:screen-1\",\n\tonboarding_continue_screen2: \"onboarding:continue:screen-2\",\n\tonboarding_continue_screen3: \"onboarding:continue:screen-3\",\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\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_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tidentifyUser: \"identify-user\",\n\tgroupLibraries: \"group-libraries\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\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.onboarding_start]: \"SliceMachine Onboarding Start\",\n\t[SegmentEventType.onboarding_skip]: \"SliceMachine Onboarding Skip\",\n\t[SegmentEventType.onboarding_continue_screenIntro]:\n\t\t\"SliceMachine Onboarding Continue Screen Intro\",\n\t[SegmentEventType.onboarding_continue_screen1]:\n\t\t\"SliceMachine Onboarding Continue Screen 1\",\n\t[SegmentEventType.onboarding_continue_screen2]:\n\t\t\"SliceMachine Onboarding Continue Screen 2\",\n\t[SegmentEventType.onboarding_continue_screen3]:\n\t\t\"SliceMachine Onboarding Continue Screen 3\",\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.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_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.identifyUser]: \"IdentifyUser\",\n\t[SegmentEventType.groupLibraries]: \"GroupLibraries\",\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} 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{ framework: string; rating: number; comment: string }\n>;\n\ntype OnboardingStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_start\n>;\n\ntype OnboardingSkipSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_skip,\n\t{ screenSkipped: number }\n>;\n\ntype OnboardingContinueScreenIntroSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screenIntro\n>;\n\ntype OnboardingContinueScreen1SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen1\n>;\n\ntype OnboardingContinueScreen2SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen2\n>;\n\ntype OnboardingContinueScreen3SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen3\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup,\n\t{ framework: string; version: string }\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open,\n\t{ framework: string; version: string }\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning,\n\t{ framework: string }\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\tframework: string;\n\t\tslicemachineVersion: string;\n\t}\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ framework: string; slicemachineVersion: string; video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\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 CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string }\n>;\n\ntype IdentifyUserSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.identifyUser\n>;\n\ntype GroupLibrariesSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.groupLibraries,\n\t{\n\t\trepoName: string;\n\t\tmanualLibsCount: number;\n\t\tdownloadedLibsCount: number;\n\t\tnpmLibsCount: number;\n\t\tdownloadedLibs: Array<string>;\n\t\tslicemachineVersion: string;\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| OnboardingStartSegmentEvent\n\t| OnboardingSkipSegmentEvent\n\t| OnboardingContinueScreenIntroSegmentEvent\n\t| OnboardingContinueScreen1SegmentEvent\n\t| OnboardingContinueScreen2SegmentEvent\n\t| OnboardingContinueScreen3SegmentEvent\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| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| IdentifyUserSegmentEvent\n\t| GroupLibrariesSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent;\n"],"names":[],"mappings":";;AAEO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iCAAiC;AAAA,EACjC,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,gBA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itType } 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\tonboarding_start: \"onboarding:start\",\n\tonboarding_skip: \"onboarding:skip\",\n\tonboarding_continue_screenIntro: \"onboarding:continue:screen-intro\",\n\tonboarding_continue_screen1: \"onboarding:continue:screen-1\",\n\tonboarding_continue_screen2: \"onboarding:continue:screen-2\",\n\tonboarding_continue_screen3: \"onboarding:continue:screen-3\",\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\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_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\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.onboarding_start]: \"SliceMachine Onboarding Start\",\n\t[SegmentEventType.onboarding_skip]: \"SliceMachine Onboarding Skip\",\n\t[SegmentEventType.onboarding_continue_screenIntro]:\n\t\t\"SliceMachine Onboarding Continue Screen Intro\",\n\t[SegmentEventType.onboarding_continue_screen1]:\n\t\t\"SliceMachine Onboarding Continue Screen 1\",\n\t[SegmentEventType.onboarding_continue_screen2]:\n\t\t\"SliceMachine Onboarding Continue Screen 2\",\n\t[SegmentEventType.onboarding_continue_screen3]:\n\t\t\"SliceMachine Onboarding Continue Screen 3\",\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.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_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\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} 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{ framework: string; rating: number; comment: string }\n>;\n\ntype OnboardingStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_start\n>;\n\ntype OnboardingSkipSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_skip,\n\t{ screenSkipped: number }\n>;\n\ntype OnboardingContinueScreenIntroSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screenIntro\n>;\n\ntype OnboardingContinueScreen1SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen1\n>;\n\ntype OnboardingContinueScreen2SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen2\n>;\n\ntype OnboardingContinueScreen3SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen3\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup,\n\t{ framework: string }\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open,\n\t{ framework: string }\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning,\n\t{ framework: string }\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\tframework: string;\n\t}\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ framework: string; video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\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 CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string }\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| OnboardingStartSegmentEvent\n\t| OnboardingSkipSegmentEvent\n\t| OnboardingContinueScreenIntroSegmentEvent\n\t| OnboardingContinueScreen1SegmentEvent\n\t| OnboardingContinueScreen2SegmentEvent\n\t| OnboardingContinueScreen3SegmentEvent\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| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent;\n"],"names":[],"mappings":";;AAEO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iCAAiC;AAAA,EACjC,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,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,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,+BAA+B,GAChD;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,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,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;;;;"}
@@ -20,8 +20,6 @@ export declare const SegmentEventType: {
20
20
  readonly customType_sliceZoneUpdated: "custom-type:slice-zone-updated";
21
21
  readonly customType_saved: "custom-type:saved";
22
22
  readonly slice_created: "slice:created";
23
- readonly identifyUser: "identify-user";
24
- readonly groupLibraries: "group-libraries";
25
23
  readonly screenshotTaken: "screenshot-taken";
26
24
  readonly changes_pushed: "changes:pushed";
27
25
  readonly changes_limitReach: "changes:limit-reach";
@@ -49,8 +47,6 @@ export declare const HumanSegmentEventType: {
49
47
  readonly "custom-type:slice-zone-updated": "SliceMachine Slicezone Updated";
50
48
  readonly "custom-type:saved": "SliceMachine Custom Type Saved";
51
49
  readonly "slice:created": "SliceMachine Slice Created";
52
- readonly "identify-user": "IdentifyUser";
53
- readonly "group-libraries": "GroupLibraries";
54
50
  readonly "screenshot-taken": "SliceMachine Screenshot Taken";
55
51
  readonly "changes:pushed": "SliceMachine Changes Pushed";
56
52
  readonly "changes:limit-reach": "SliceMachine Changes Limit Reach";
@@ -86,11 +82,9 @@ type OnboardingContinueScreen2SegmentEvent = SegmentEvent<typeof SegmentEventTyp
86
82
  type OnboardingContinueScreen3SegmentEvent = SegmentEvent<typeof SegmentEventType.onboarding_continue_screen3>;
87
83
  type SliceSimulatorSetupSegmentEvent = SegmentEvent<typeof SegmentEventType.sliceSimulator_setup, {
88
84
  framework: string;
89
- version: string;
90
85
  }>;
91
86
  type SliceSimulatorOpenSegmentEvent = SegmentEvent<typeof SegmentEventType.sliceSimulator_open, {
92
87
  framework: string;
93
- version: string;
94
88
  }>;
95
89
  type SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<typeof SegmentEventType.sliceSimulator_isNotRunning, {
96
90
  framework: string;
@@ -102,11 +96,9 @@ type PageViewSegmentEvent = SegmentEvent<typeof SegmentEventType.pageView, {
102
96
  title: string;
103
97
  referrer: string;
104
98
  framework: string;
105
- slicemachineVersion: string;
106
99
  }>;
107
100
  type OpenVideoTutorialsSegmentEvent = SegmentEvent<typeof SegmentEventType.openVideoTutorials, {
108
101
  framework: string;
109
- slicemachineVersion: string;
110
102
  video: string;
111
103
  }>;
112
104
  type CustomTypeCreatedSegmentEvent = SegmentEvent<typeof SegmentEventType.customType_created, {
@@ -133,15 +125,6 @@ type SliceCreatedSegmentEvent = SegmentEvent<typeof SegmentEventType.slice_creat
133
125
  name: string;
134
126
  library: string;
135
127
  }>;
136
- type IdentifyUserSegmentEvent = SegmentEvent<typeof SegmentEventType.identifyUser>;
137
- type GroupLibrariesSegmentEvent = SegmentEvent<typeof SegmentEventType.groupLibraries, {
138
- repoName: string;
139
- manualLibsCount: number;
140
- downloadedLibsCount: number;
141
- npmLibsCount: number;
142
- downloadedLibs: Array<string>;
143
- slicemachineVersion: string;
144
- }>;
145
128
  type ScreenshotTakenSegmentEvent = SegmentEvent<typeof SegmentEventType.screenshotTaken, {
146
129
  type: "custom" | "automatic";
147
130
  method: "fromSimulator" | "upload" | "dragAndDrop";
@@ -164,5 +147,5 @@ type ChangesLimitReachSegmentEvent = SegmentEvent<typeof SegmentEventType.change
164
147
  type EditorWidgetUsedSegmentEvent = SegmentEvent<typeof SegmentEventType.editor_widgetUsed, {
165
148
  sliceId: string;
166
149
  }>;
167
- export type SegmentEvents = CommandInitStartSegmentEvent | CommandInitIdentifySegmentEvent | CommandInitEndSegmentEvent | ReviewSegmentEvent | OnboardingStartSegmentEvent | OnboardingSkipSegmentEvent | OnboardingContinueScreenIntroSegmentEvent | OnboardingContinueScreen1SegmentEvent | OnboardingContinueScreen2SegmentEvent | OnboardingContinueScreen3SegmentEvent | SliceSimulatorSetupSegmentEvent | SliceSimulatorOpenSegmentEvent | SliceSimulatorIsNotRunningSegmentEvent | PageViewSegmentEvent | OpenVideoTutorialsSegmentEvent | CustomTypeCreatedSegmentEvent | CustomTypeFieldAddedSegmentEvent | CustomTypeSliceZoneUpdatedSegmentEvent | CustomTypeSavedSegmentEvent | SliceCreatedSegmentEvent | IdentifyUserSegmentEvent | GroupLibrariesSegmentEvent | ScreenshotTakenSegmentEvent | ChangesPushedSegmentEvent | ChangesLimitReachSegmentEvent | EditorWidgetUsedSegmentEvent;
150
+ export type SegmentEvents = CommandInitStartSegmentEvent | CommandInitIdentifySegmentEvent | CommandInitEndSegmentEvent | ReviewSegmentEvent | OnboardingStartSegmentEvent | OnboardingSkipSegmentEvent | OnboardingContinueScreenIntroSegmentEvent | OnboardingContinueScreen1SegmentEvent | OnboardingContinueScreen2SegmentEvent | OnboardingContinueScreen3SegmentEvent | SliceSimulatorSetupSegmentEvent | SliceSimulatorOpenSegmentEvent | SliceSimulatorIsNotRunningSegmentEvent | PageViewSegmentEvent | OpenVideoTutorialsSegmentEvent | CustomTypeCreatedSegmentEvent | CustomTypeFieldAddedSegmentEvent | CustomTypeSliceZoneUpdatedSegmentEvent | CustomTypeSavedSegmentEvent | SliceCreatedSegmentEvent | ScreenshotTakenSegmentEvent | ChangesPushedSegmentEvent | ChangesLimitReachSegmentEvent | EditorWidgetUsedSegmentEvent;
168
151
  export {};
@@ -19,8 +19,6 @@ const SegmentEventType = {
19
19
  customType_sliceZoneUpdated: "custom-type:slice-zone-updated",
20
20
  customType_saved: "custom-type:saved",
21
21
  slice_created: "slice:created",
22
- identifyUser: "identify-user",
23
- groupLibraries: "group-libraries",
24
22
  screenshotTaken: "screenshot-taken",
25
23
  changes_pushed: "changes:pushed",
26
24
  changes_limitReach: "changes:limit-reach",
@@ -47,8 +45,6 @@ const HumanSegmentEventType = {
47
45
  [SegmentEventType.customType_sliceZoneUpdated]: "SliceMachine Slicezone Updated",
48
46
  [SegmentEventType.customType_saved]: "SliceMachine Custom Type Saved",
49
47
  [SegmentEventType.slice_created]: "SliceMachine Slice Created",
50
- [SegmentEventType.identifyUser]: "IdentifyUser",
51
- [SegmentEventType.groupLibraries]: "GroupLibraries",
52
48
  [SegmentEventType.screenshotTaken]: "SliceMachine Screenshot Taken",
53
49
  [SegmentEventType.changes_pushed]: "SliceMachine Changes Pushed",
54
50
  [SegmentEventType.changes_limitReach]: "SliceMachine Changes Limit Reach",
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../../src/managers/telemetry/types.ts"],"sourcesContent":["import 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\tonboarding_start: \"onboarding:start\",\n\tonboarding_skip: \"onboarding:skip\",\n\tonboarding_continue_screenIntro: \"onboarding:continue:screen-intro\",\n\tonboarding_continue_screen1: \"onboarding:continue:screen-1\",\n\tonboarding_continue_screen2: \"onboarding:continue:screen-2\",\n\tonboarding_continue_screen3: \"onboarding:continue:screen-3\",\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\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_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tidentifyUser: \"identify-user\",\n\tgroupLibraries: \"group-libraries\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\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.onboarding_start]: \"SliceMachine Onboarding Start\",\n\t[SegmentEventType.onboarding_skip]: \"SliceMachine Onboarding Skip\",\n\t[SegmentEventType.onboarding_continue_screenIntro]:\n\t\t\"SliceMachine Onboarding Continue Screen Intro\",\n\t[SegmentEventType.onboarding_continue_screen1]:\n\t\t\"SliceMachine Onboarding Continue Screen 1\",\n\t[SegmentEventType.onboarding_continue_screen2]:\n\t\t\"SliceMachine Onboarding Continue Screen 2\",\n\t[SegmentEventType.onboarding_continue_screen3]:\n\t\t\"SliceMachine Onboarding Continue Screen 3\",\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.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_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\n\t[SegmentEventType.identifyUser]: \"IdentifyUser\",\n\t[SegmentEventType.groupLibraries]: \"GroupLibraries\",\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} 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{ framework: string; rating: number; comment: string }\n>;\n\ntype OnboardingStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_start\n>;\n\ntype OnboardingSkipSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_skip,\n\t{ screenSkipped: number }\n>;\n\ntype OnboardingContinueScreenIntroSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screenIntro\n>;\n\ntype OnboardingContinueScreen1SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen1\n>;\n\ntype OnboardingContinueScreen2SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen2\n>;\n\ntype OnboardingContinueScreen3SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen3\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup,\n\t{ framework: string; version: string }\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open,\n\t{ framework: string; version: string }\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning,\n\t{ framework: string }\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\tframework: string;\n\t\tslicemachineVersion: string;\n\t}\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ framework: string; slicemachineVersion: string; video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\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 CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string }\n>;\n\ntype IdentifyUserSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.identifyUser\n>;\n\ntype GroupLibrariesSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.groupLibraries,\n\t{\n\t\trepoName: string;\n\t\tmanualLibsCount: number;\n\t\tdownloadedLibsCount: number;\n\t\tnpmLibsCount: number;\n\t\tdownloadedLibs: Array<string>;\n\t\tslicemachineVersion: string;\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| OnboardingStartSegmentEvent\n\t| OnboardingSkipSegmentEvent\n\t| OnboardingContinueScreenIntroSegmentEvent\n\t| OnboardingContinueScreen1SegmentEvent\n\t| OnboardingContinueScreen2SegmentEvent\n\t| OnboardingContinueScreen3SegmentEvent\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| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| IdentifyUserSegmentEvent\n\t| GroupLibrariesSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent;\n"],"names":[],"mappings":"AAEO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iCAAiC;AAAA,EACjC,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,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Type } 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\tonboarding_start: \"onboarding:start\",\n\tonboarding_skip: \"onboarding:skip\",\n\tonboarding_continue_screenIntro: \"onboarding:continue:screen-intro\",\n\tonboarding_continue_screen1: \"onboarding:continue:screen-1\",\n\tonboarding_continue_screen2: \"onboarding:continue:screen-2\",\n\tonboarding_continue_screen3: \"onboarding:continue:screen-3\",\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\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_saved: \"custom-type:saved\",\n\tslice_created: \"slice:created\",\n\tscreenshotTaken: \"screenshot-taken\",\n\tchanges_pushed: \"changes:pushed\",\n\tchanges_limitReach: \"changes:limit-reach\",\n\teditor_widgetUsed: \"editor:widget-used\",\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.onboarding_start]: \"SliceMachine Onboarding Start\",\n\t[SegmentEventType.onboarding_skip]: \"SliceMachine Onboarding Skip\",\n\t[SegmentEventType.onboarding_continue_screenIntro]:\n\t\t\"SliceMachine Onboarding Continue Screen Intro\",\n\t[SegmentEventType.onboarding_continue_screen1]:\n\t\t\"SliceMachine Onboarding Continue Screen 1\",\n\t[SegmentEventType.onboarding_continue_screen2]:\n\t\t\"SliceMachine Onboarding Continue Screen 2\",\n\t[SegmentEventType.onboarding_continue_screen3]:\n\t\t\"SliceMachine Onboarding Continue Screen 3\",\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.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_saved]: \"SliceMachine Custom Type Saved\",\n\t[SegmentEventType.slice_created]: \"SliceMachine Slice Created\",\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} 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{ framework: string; rating: number; comment: string }\n>;\n\ntype OnboardingStartSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_start\n>;\n\ntype OnboardingSkipSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_skip,\n\t{ screenSkipped: number }\n>;\n\ntype OnboardingContinueScreenIntroSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screenIntro\n>;\n\ntype OnboardingContinueScreen1SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen1\n>;\n\ntype OnboardingContinueScreen2SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen2\n>;\n\ntype OnboardingContinueScreen3SegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.onboarding_continue_screen3\n>;\n\ntype SliceSimulatorSetupSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_setup,\n\t{ framework: string }\n>;\n\ntype SliceSimulatorOpenSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_open,\n\t{ framework: string }\n>;\n\ntype SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.sliceSimulator_isNotRunning,\n\t{ framework: string }\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\tframework: string;\n\t}\n>;\n\ntype OpenVideoTutorialsSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.openVideoTutorials,\n\t{ framework: string; video: string }\n>;\n\ntype CustomTypeCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_created,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\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 CustomTypeSavedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.customType_saved,\n\t{ id: string; name: string; type: \"repeatable\" | \"single\" }\n>;\n\ntype SliceCreatedSegmentEvent = SegmentEvent<\n\ttypeof SegmentEventType.slice_created,\n\t{ id: string; name: string; library: string }\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| OnboardingStartSegmentEvent\n\t| OnboardingSkipSegmentEvent\n\t| OnboardingContinueScreenIntroSegmentEvent\n\t| OnboardingContinueScreen1SegmentEvent\n\t| OnboardingContinueScreen2SegmentEvent\n\t| OnboardingContinueScreen3SegmentEvent\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| CustomTypeSavedSegmentEvent\n\t| SliceCreatedSegmentEvent\n\t| ScreenshotTakenSegmentEvent\n\t| ChangesPushedSegmentEvent\n\t| ChangesLimitReachSegmentEvent\n\t| EditorWidgetUsedSegmentEvent;\n"],"names":[],"mappings":"AAEO,MAAM,mBAAmB;AAAA,EAC/B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,iCAAiC;AAAA,EACjC,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,6BAA6B;AAAA,EAC7B,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,6BAA6B;AAAA,EAC7B,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,6BAA6B;AAAA,EAC7B,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,oBAAoB;AAAA,EACpB,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,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,+BAA+B,GAChD;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,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,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,qBAAqB,GACtC;AAAA,EACD,CAAC,iBAAiB,2BAA2B,GAC5C;AAAA,EACD,CAAC,iBAAiB,gBAAgB,GAAG;AAAA,EACrC,CAAC,iBAAiB,aAAa,GAAG;AAAA,EAClC,CAAC,iBAAiB,eAAe,GAAG;AAAA,EACpC,CAAC,iBAAiB,cAAc,GAAG;AAAA,EACnC,CAAC,iBAAiB,kBAAkB,GAAG;AAAA,EACvC,CAAC,iBAAiB,iBAAiB,GAAG;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/manager",
3
- "version": "0.1.1-dev-plugins-validation.1",
3
+ "version": "0.1.1-dev-plugins-validation.0",
4
4
  "description": "Manage all aspects of a Slice Machine project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,7 +63,7 @@
63
63
  "@antfu/ni": "^0.20.0",
64
64
  "@prismicio/custom-types-client": "^1.0.2",
65
65
  "@prismicio/types-internal": "^1.5.3",
66
- "@slicemachine/plugin-kit": "0.1.8-dev-plugins-validation.1",
66
+ "@slicemachine/plugin-kit": "0.1.8-dev-plugins-validation.0",
67
67
  "@wooorm/starry-night": "^1.6.0",
68
68
  "analytics-node": "^6.2.0",
69
69
  "cookie": "^0.5.0",
@@ -135,5 +135,5 @@
135
135
  "publishConfig": {
136
136
  "access": "public"
137
137
  },
138
- "gitHead": "be509347c1cfaed23c9b9f714051a38436d4d9de"
138
+ "gitHead": "65a2f9c1a92fac240e7b7ba8074758e757661b94"
139
139
  }
@@ -1,3 +1,4 @@
1
+ import { addTrailingSlash } from "../lib/addTrailingSlash";
1
2
  import { APPLICATION_MODE } from "./APPLICATION_MODE";
2
3
 
3
4
  export type APIEndpoints = {
@@ -12,11 +13,13 @@ export const API_ENDPOINTS: APIEndpoints = (() => {
12
13
  switch (process.env.SM_ENV) {
13
14
  case APPLICATION_MODE.Development: {
14
15
  const apiEndpoints = {
15
- PrismicWroom: process.env.wroom_endpoint,
16
- PrismicAuthentication: process.env.authentication_server_endpoint,
17
- PrismicModels: process.env.customtypesapi_endpoint,
18
- PrismicUser: process.env.user_service_endpoint,
19
- AwsAclProvider: process.env.acl_provider_endpoint,
16
+ PrismicWroom: addTrailingSlash(process.env.wroom_endpoint),
17
+ PrismicAuthentication: addTrailingSlash(
18
+ process.env.authentication_server_endpoint,
19
+ ),
20
+ PrismicModels: addTrailingSlash(process.env.customtypesapi_endpoint),
21
+ PrismicUser: addTrailingSlash(process.env.user_service_endpoint),
22
+ AwsAclProvider: addTrailingSlash(process.env.acl_provider_endpoint),
20
23
  };
21
24
 
22
25
  const missingAPIEndpoints = Object.keys(apiEndpoints).filter((key) => {
@@ -0,0 +1,5 @@
1
+ export const addTrailingSlash = (
2
+ url: string | undefined,
3
+ ): string | undefined => {
4
+ return url?.replace(/\/?$/, "/");
5
+ };
@@ -44,7 +44,6 @@ type SliceMachineManagerGetStateReturnType = {
44
44
  repo: string;
45
45
  changelog?: PackageChangelog;
46
46
  packageManager: PackageManager;
47
- mockConfig: unknown; // TODO: Remove
48
47
  framework: unknown; // TODO: Remove
49
48
  };
50
49
  libraries: {
@@ -67,7 +66,6 @@ type SliceMachineManagerGetStateReturnType = {
67
66
  }
68
67
  >;
69
68
  mock?: SharedSliceContent[];
70
- mockConfig: unknown; // TODO: Remove
71
69
  }[];
72
70
  meta: {
73
71
  name?: string;
@@ -225,7 +223,6 @@ export class SliceMachineManager {
225
223
  ),
226
224
  localSliceSimulatorURL: sliceMachineConfig.localSliceSimulatorURL,
227
225
  },
228
- mockConfig: {},
229
226
  packageManager,
230
227
  repo: sliceMachineConfig.repositoryName,
231
228
  intercomHash: profile?.intercomHash,
@@ -305,7 +302,6 @@ export class SliceMachineManager {
305
302
  model,
306
303
  screenshots,
307
304
  mock: mocks,
308
- mockConfig: {}, // TODO: This property can probably be removed.
309
305
  });
310
306
  }
311
307
  }),
@@ -328,7 +324,15 @@ export class SliceMachineManager {
328
324
  );
329
325
  }
330
326
 
331
- return libraries;
327
+ // Preserve library order from config file
328
+ return libraries.sort((library1, library2) => {
329
+ const libraryIndex1 =
330
+ sliceMachineConfig.libraries?.indexOf(library1.name) || 0;
331
+ const libraryIndex2 =
332
+ sliceMachineConfig.libraries?.indexOf(library2.name) || 0;
333
+
334
+ return Math.sign(libraryIndex1 - libraryIndex2);
335
+ });
332
336
  }
333
337
 
334
338
  private async _getCustomTypes(): Promise<
@@ -14,6 +14,11 @@ import {
14
14
  SegmentEvents,
15
15
  } from "./types";
16
16
 
17
+ type TelemetryManagerInitTelemetryArgs = {
18
+ appName: string;
19
+ appVersion: string;
20
+ };
21
+
17
22
  type TelemetryManagerTrackArgs = SegmentEvents;
18
23
 
19
24
  type TelemetryManagerIdentifyArgs = {
@@ -21,6 +26,21 @@ type TelemetryManagerIdentifyArgs = {
21
26
  intercomHash: string;
22
27
  };
23
28
 
29
+ type TelemetryManagerGroupArgs = {
30
+ repositoryName: string;
31
+ manualLibsCount: number;
32
+ downloadedLibsCount: number;
33
+ npmLibsCount: number;
34
+ downloadedLibs: string[];
35
+ };
36
+
37
+ type TelemetryManagerContext = {
38
+ app: {
39
+ name: string;
40
+ version: string;
41
+ };
42
+ };
43
+
24
44
  function assertTelemetryInitialized(
25
45
  segmentClient: SegmentClient | undefined,
26
46
  ): asserts segmentClient is NonNullable<typeof segmentClient> {
@@ -35,8 +55,9 @@ export class TelemetryManager extends BaseManager {
35
55
  private _segmentClient: SegmentClient | undefined = undefined;
36
56
  private _anonymousID: string | undefined = undefined;
37
57
  private _userID: string | undefined = undefined;
58
+ private _context: TelemetryManagerContext | undefined = undefined;
38
59
 
39
- async initTelemetry(): Promise<void> {
60
+ async initTelemetry(args: TelemetryManagerInitTelemetryArgs): Promise<void> {
40
61
  if (this._segmentClient) {
41
62
  // Prevent subsequent initializations.
42
63
  return;
@@ -55,6 +76,7 @@ export class TelemetryManager extends BaseManager {
55
76
  },
56
77
  });
57
78
  this._anonymousID = randomUUID();
79
+ this._context = { app: { name: args.appName, version: args.appVersion } };
58
80
  }
59
81
 
60
82
  // TODO: Should `userId` be automatically populated by the logged in
@@ -67,7 +89,7 @@ export class TelemetryManager extends BaseManager {
67
89
  userId?: string;
68
90
  anonymousId?: string;
69
91
  properties?: Record<string, unknown>;
70
- context?: {
92
+ context?: Partial<TelemetryManagerContext> & {
71
93
  groupId?: {
72
94
  Repository?: string;
73
95
  };
@@ -75,9 +97,11 @@ export class TelemetryManager extends BaseManager {
75
97
  } = {
76
98
  event: HumanSegmentEventType[event],
77
99
  properties: {
100
+ nodeVersion: process.versions.node,
78
101
  repo: repository,
79
102
  ...properties,
80
103
  },
104
+ context: { ...this._context },
81
105
  };
82
106
 
83
107
  if (this._userID) {
@@ -117,20 +141,22 @@ export class TelemetryManager extends BaseManager {
117
141
  // by the logged in user? We already have their info via
118
142
  // UserRepository.
119
143
  identify(args: TelemetryManagerIdentifyArgs): Promise<void> {
144
+ const payload = {
145
+ userId: args.userID,
146
+ anonymousId: this._anonymousID,
147
+ integrations: {
148
+ Intercom: {
149
+ user_hash: args.intercomHash,
150
+ },
151
+ },
152
+ context: { ...this._context },
153
+ };
154
+
155
+ this._userID = args.userID;
156
+
120
157
  return new Promise((resolve) => {
121
158
  assertTelemetryInitialized(this._segmentClient);
122
159
 
123
- const payload = {
124
- userId: args.userID,
125
- anonymousId: this._anonymousID,
126
- integrations: {
127
- Intercom: {
128
- user_hash: args.intercomHash,
129
- },
130
- },
131
- };
132
- this._userID = args.userID;
133
-
134
160
  // TODO: Make sure client fails gracefully when no internet connection
135
161
  this._segmentClient.identify(payload, (maybeError?: Error) => {
136
162
  if (maybeError) {
@@ -143,6 +169,44 @@ export class TelemetryManager extends BaseManager {
143
169
  });
144
170
  }
145
171
 
172
+ group(args: TelemetryManagerGroupArgs): Promise<void> {
173
+ const { repositoryName, ...traits } = args;
174
+
175
+ const payload: {
176
+ groupId: string;
177
+ userId?: string;
178
+ anonymousId?: string;
179
+ traits?: Record<string, unknown>;
180
+ context?: Partial<TelemetryManagerContext>;
181
+ } = {
182
+ groupId: repositoryName,
183
+ traits,
184
+ context: { ...this._context },
185
+ };
186
+
187
+ if (this._userID) {
188
+ payload.userId = this._userID;
189
+ } else {
190
+ payload.anonymousId = this._anonymousID;
191
+ }
192
+
193
+ return new Promise((resolve) => {
194
+ assertTelemetryInitialized(this._segmentClient);
195
+
196
+ this._segmentClient.group(
197
+ payload as Parameters<typeof this._segmentClient.group>[0],
198
+ (maybeError?: Error) => {
199
+ if (maybeError) {
200
+ // TODO: Not sure how we want to deal with that
201
+ console.warn(`An error occurred during Segment group`, maybeError);
202
+ }
203
+
204
+ resolve();
205
+ },
206
+ );
207
+ });
208
+ }
209
+
146
210
  async checkIsTelemetryEnabled(): Promise<boolean> {
147
211
  let root: string;
148
212
  try {
@@ -21,8 +21,6 @@ export const SegmentEventType = {
21
21
  customType_sliceZoneUpdated: "custom-type:slice-zone-updated",
22
22
  customType_saved: "custom-type:saved",
23
23
  slice_created: "slice:created",
24
- identifyUser: "identify-user",
25
- groupLibraries: "group-libraries",
26
24
  screenshotTaken: "screenshot-taken",
27
25
  changes_pushed: "changes:pushed",
28
26
  changes_limitReach: "changes:limit-reach",
@@ -59,8 +57,6 @@ export const HumanSegmentEventType = {
59
57
  "SliceMachine Slicezone Updated",
60
58
  [SegmentEventType.customType_saved]: "SliceMachine Custom Type Saved",
61
59
  [SegmentEventType.slice_created]: "SliceMachine Slice Created",
62
- [SegmentEventType.identifyUser]: "IdentifyUser",
63
- [SegmentEventType.groupLibraries]: "GroupLibraries",
64
60
  [SegmentEventType.screenshotTaken]: "SliceMachine Screenshot Taken",
65
61
  [SegmentEventType.changes_pushed]: "SliceMachine Changes Pushed",
66
62
  [SegmentEventType.changes_limitReach]: "SliceMachine Changes Limit Reach",
@@ -128,12 +124,12 @@ type OnboardingContinueScreen3SegmentEvent = SegmentEvent<
128
124
 
129
125
  type SliceSimulatorSetupSegmentEvent = SegmentEvent<
130
126
  typeof SegmentEventType.sliceSimulator_setup,
131
- { framework: string; version: string }
127
+ { framework: string }
132
128
  >;
133
129
 
134
130
  type SliceSimulatorOpenSegmentEvent = SegmentEvent<
135
131
  typeof SegmentEventType.sliceSimulator_open,
136
- { framework: string; version: string }
132
+ { framework: string }
137
133
  >;
138
134
 
139
135
  type SliceSimulatorIsNotRunningSegmentEvent = SegmentEvent<
@@ -150,13 +146,12 @@ type PageViewSegmentEvent = SegmentEvent<
150
146
  title: string;
151
147
  referrer: string;
152
148
  framework: string;
153
- slicemachineVersion: string;
154
149
  }
155
150
  >;
156
151
 
157
152
  type OpenVideoTutorialsSegmentEvent = SegmentEvent<
158
153
  typeof SegmentEventType.openVideoTutorials,
159
- { framework: string; slicemachineVersion: string; video: string }
154
+ { framework: string; video: string }
160
155
  >;
161
156
 
162
157
  type CustomTypeCreatedSegmentEvent = SegmentEvent<
@@ -189,22 +184,6 @@ type SliceCreatedSegmentEvent = SegmentEvent<
189
184
  { id: string; name: string; library: string }
190
185
  >;
191
186
 
192
- type IdentifyUserSegmentEvent = SegmentEvent<
193
- typeof SegmentEventType.identifyUser
194
- >;
195
-
196
- type GroupLibrariesSegmentEvent = SegmentEvent<
197
- typeof SegmentEventType.groupLibraries,
198
- {
199
- repoName: string;
200
- manualLibsCount: number;
201
- downloadedLibsCount: number;
202
- npmLibsCount: number;
203
- downloadedLibs: Array<string>;
204
- slicemachineVersion: string;
205
- }
206
- >;
207
-
208
187
  type ScreenshotTakenSegmentEvent = SegmentEvent<
209
188
  typeof SegmentEventType.screenshotTaken,
210
189
  {
@@ -260,8 +239,6 @@ export type SegmentEvents =
260
239
  | CustomTypeSliceZoneUpdatedSegmentEvent
261
240
  | CustomTypeSavedSegmentEvent
262
241
  | SliceCreatedSegmentEvent
263
- | IdentifyUserSegmentEvent
264
- | GroupLibrariesSegmentEvent
265
242
  | ScreenshotTakenSegmentEvent
266
243
  | ChangesPushedSegmentEvent
267
244
  | ChangesLimitReachSegmentEvent