@slicemachine/manager 0.17.4-dev-next-release.1 → 0.17.4-dev-next-release.2

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 (37) hide show
  1. package/dist/_node_modules/r19/dist/client/createRPCClient.cjs +1 -9
  2. package/dist/_node_modules/r19/dist/client/createRPCClient.cjs.map +1 -1
  3. package/dist/_node_modules/r19/dist/client/createRPCClient.js +1 -9
  4. package/dist/_node_modules/r19/dist/client/createRPCClient.js.map +1 -1
  5. package/dist/_node_modules/r19/dist/handleRPCRequest.cjs +1 -1
  6. package/dist/_node_modules/r19/dist/handleRPCRequest.cjs.map +1 -1
  7. package/dist/_node_modules/r19/dist/handleRPCRequest.js +1 -1
  8. package/dist/_node_modules/r19/dist/handleRPCRequest.js.map +1 -1
  9. package/dist/lib/findEnvironment.cjs +12 -0
  10. package/dist/lib/findEnvironment.cjs.map +1 -0
  11. package/dist/lib/findEnvironment.d.ts +2 -0
  12. package/dist/lib/findEnvironment.js +12 -0
  13. package/dist/lib/findEnvironment.js.map +1 -0
  14. package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +22 -3
  15. package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
  16. package/dist/managers/prismicRepository/PrismicRepositoryManager.d.ts +4 -1
  17. package/dist/managers/prismicRepository/PrismicRepositoryManager.js +22 -3
  18. package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
  19. package/dist/managers/project/ProjectManager.cjs +18 -0
  20. package/dist/managers/project/ProjectManager.cjs.map +1 -1
  21. package/dist/managers/project/ProjectManager.d.ts +6 -0
  22. package/dist/managers/project/ProjectManager.js +19 -1
  23. package/dist/managers/project/ProjectManager.js.map +1 -1
  24. package/dist/managers/telemetry/TelemetryManager.cjs +14 -0
  25. package/dist/managers/telemetry/TelemetryManager.cjs.map +1 -1
  26. package/dist/managers/telemetry/TelemetryManager.d.ts +3 -1
  27. package/dist/managers/telemetry/TelemetryManager.js +14 -0
  28. package/dist/managers/telemetry/TelemetryManager.js.map +1 -1
  29. package/package.json +4 -4
  30. package/src/lib/findEnvironment.ts +14 -0
  31. package/src/managers/prismicRepository/PrismicRepositoryManager.ts +41 -3
  32. package/src/managers/project/ProjectManager.ts +56 -1
  33. package/src/managers/telemetry/TelemetryManager.ts +24 -1
  34. package/dist/_node_modules/r19/dist/lib/isPlainObject.cjs +0 -11
  35. package/dist/_node_modules/r19/dist/lib/isPlainObject.cjs.map +0 -1
  36. package/dist/_node_modules/r19/dist/lib/isPlainObject.js +0 -11
  37. package/dist/_node_modules/r19/dist/lib/isPlainObject.js.map +0 -1
@@ -15,6 +15,7 @@ import { DecodeError } from "../../lib/DecodeError";
15
15
  import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
16
16
  import { decodeHookResult } from "../../lib/decodeHookResult";
17
17
  import { decodeSliceMachineConfig } from "../../lib/decodeSliceMachineConfig";
18
+ import { findEnvironment } from "../../lib/findEnvironment";
18
19
  import { format } from "../../lib/format";
19
20
  import { installDependencies } from "../../lib/installDependencies";
20
21
  import { locateFileUpward } from "../../lib/locateFileUpward";
@@ -25,13 +26,19 @@ import {
25
26
  OnlyHookErrors,
26
27
  } from "../../types";
27
28
 
28
- import { SliceMachineError, InternalError, PluginError } from "../../errors";
29
+ import {
30
+ SliceMachineError,
31
+ InternalError,
32
+ PluginError,
33
+ UnexpectedDataError,
34
+ } from "../../errors";
29
35
 
30
36
  import { SLICE_MACHINE_CONFIG_FILENAME } from "../../constants/SLICE_MACHINE_CONFIG_FILENAME";
31
37
  import { TS_CONFIG_FILENAME } from "../../constants/TS_CONFIG_FILENAME";
32
38
  import { SLICE_MACHINE_NPM_PACKAGE_NAME } from "../../constants/SLICE_MACHINE_NPM_PACKAGE_NAME";
33
39
 
34
40
  import { BaseManager } from "../BaseManager";
41
+ import { Environment } from "../prismicRepository/types";
35
42
 
36
43
  type ProjectManagerGetSliceMachineConfigPathArgs = {
37
44
  ignoreCache?: boolean;
@@ -78,10 +85,15 @@ type ProjectManagerUpdateEnvironmentArgs = {
78
85
  environment: string | undefined;
79
86
  };
80
87
 
88
+ type ProjectManagerFetchActiveEnvironmentReturnType = {
89
+ activeEnvironment: Environment;
90
+ };
91
+
81
92
  export class ProjectManager extends BaseManager {
82
93
  private _cachedRoot: string | undefined;
83
94
  private _cachedSliceMachineConfigPath: string | undefined;
84
95
  private _cachedSliceMachineConfig: SliceMachineConfig | undefined;
96
+ private _cachedEnvironments: Environment[] | undefined;
85
97
 
86
98
  async getSliceMachineConfigPath(
87
99
  args?: ProjectManagerGetSliceMachineConfigPathArgs,
@@ -427,6 +439,49 @@ export class ProjectManager extends BaseManager {
427
439
  };
428
440
  }
429
441
 
442
+ async fetchActiveEnvironment(): Promise<ProjectManagerFetchActiveEnvironmentReturnType> {
443
+ const { environment: activeEnvironmentDomain } =
444
+ await this.readEnvironment();
445
+
446
+ // We can assume an environment cannot change its kind. If the
447
+ // environment exists in the cached list, we are confident it
448
+ // will not change.
449
+ const cachedActiveEnvironment = findEnvironment(
450
+ activeEnvironmentDomain,
451
+ this._cachedEnvironments || [],
452
+ );
453
+ if (cachedActiveEnvironment) {
454
+ return { activeEnvironment: cachedActiveEnvironment };
455
+ }
456
+
457
+ // If the environment is not in the cached environments list, we
458
+ // must fetch a fresh list and set the cache.
459
+ const { environments } = await this.prismicRepository.fetchEnvironments();
460
+ // TODO: Remove the wrapping if statement when
461
+ // `this.prismicRepository.fetchEnvironments()` is able to throw
462
+ // normally. The method returns an object with an `error`
463
+ // property at the time of this writing, which means we need to
464
+ // check if the `environments` property exists.
465
+ if (environments) {
466
+ this._cachedEnvironments = environments;
467
+ }
468
+
469
+ const activeEnvironment = findEnvironment(
470
+ activeEnvironmentDomain,
471
+ this._cachedEnvironments || [],
472
+ );
473
+
474
+ if (!activeEnvironment) {
475
+ throw new UnexpectedDataError(
476
+ `The active environment (${
477
+ activeEnvironmentDomain ?? "Production"
478
+ }) does not match one of the repository's environments.`,
479
+ );
480
+ }
481
+
482
+ return { activeEnvironment };
483
+ }
484
+
430
485
  private async _assertAdapterSupportsEnvironments(): Promise<void> {
431
486
  assertPluginsInitialized(this.sliceMachinePluginRunner);
432
487
 
@@ -13,13 +13,16 @@ import {
13
13
  HumanSegmentEventTypes,
14
14
  SegmentEvents,
15
15
  } from "./types";
16
+ import { Environment } from "../prismicRepository/types";
16
17
 
17
18
  type TelemetryManagerInitTelemetryArgs = {
18
19
  appName: string;
19
20
  appVersion: string;
20
21
  };
21
22
 
22
- type TelemetryManagerTrackArgs = SegmentEvents;
23
+ type TelemetryManagerTrackArgs = SegmentEvents & {
24
+ _includeEnvironmentKind?: boolean;
25
+ };
23
26
 
24
27
  type TelemetryManagerIdentifyArgs = {
25
28
  userID: string;
@@ -97,6 +100,25 @@ export class TelemetryManager extends BaseManager {
97
100
  }
98
101
  }
99
102
 
103
+ let environmentKind: Environment["kind"] | "_unknown" | undefined =
104
+ undefined;
105
+ if (args._includeEnvironmentKind) {
106
+ if (this.project.checkSupportsEnvironments()) {
107
+ try {
108
+ const { activeEnvironment } =
109
+ await this.project.fetchActiveEnvironment();
110
+ environmentKind = activeEnvironment.kind;
111
+ } catch {
112
+ environmentKind = "_unknown";
113
+ }
114
+ } else {
115
+ // Assume only the production environment can be
116
+ // used if the project's adapter does not
117
+ // support environments.
118
+ environmentKind = "prod";
119
+ }
120
+ }
121
+
100
122
  const payload: {
101
123
  event: HumanSegmentEventTypes;
102
124
  userId?: string;
@@ -111,6 +133,7 @@ export class TelemetryManager extends BaseManager {
111
133
  event: HumanSegmentEventType[event],
112
134
  properties: {
113
135
  nodeVersion: process.versions.node,
136
+ environmentKind,
114
137
  ...properties,
115
138
  },
116
139
  context: { ...this._context },
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const isPlainObject = (value) => {
4
- if (typeof value !== "object" || value === null) {
5
- return false;
6
- }
7
- const prototype = Object.getPrototypeOf(value);
8
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
9
- };
10
- exports.isPlainObject = isPlainObject;
11
- //# sourceMappingURL=isPlainObject.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPlainObject.cjs","sources":["../../../../../../../node_modules/r19/dist/lib/isPlainObject.js"],"sourcesContent":["const isPlainObject = (value) => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);\n};\nexport {\n isPlainObject\n};\n//# sourceMappingURL=isPlainObject.js.map\n"],"names":[],"mappings":";;AAAK,MAAC,gBAAgB,CAAC,UAAU;AAC/B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACR;AACD,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,UAAQ,cAAc,QAAQ,cAAc,OAAO,aAAa,OAAO,eAAe,SAAS,MAAM,SAAS,EAAE,OAAO,eAAe,UAAU,EAAE,OAAO,YAAY;AACvK;;","x_google_ignoreList":[0]}
@@ -1,11 +0,0 @@
1
- const isPlainObject = (value) => {
2
- if (typeof value !== "object" || value === null) {
3
- return false;
4
- }
5
- const prototype = Object.getPrototypeOf(value);
6
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
7
- };
8
- export {
9
- isPlainObject
10
- };
11
- //# sourceMappingURL=isPlainObject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPlainObject.js","sources":["../../../../../../../node_modules/r19/dist/lib/isPlainObject.js"],"sourcesContent":["const isPlainObject = (value) => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);\n};\nexport {\n isPlainObject\n};\n//# sourceMappingURL=isPlainObject.js.map\n"],"names":[],"mappings":"AAAK,MAAC,gBAAgB,CAAC,UAAU;AAC/B,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACR;AACD,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,UAAQ,cAAc,QAAQ,cAAc,OAAO,aAAa,OAAO,eAAe,SAAS,MAAM,SAAS,EAAE,OAAO,eAAe,UAAU,EAAE,OAAO,YAAY;AACvK;","x_google_ignoreList":[0]}