@epigraph/epigraph-std-lib 3.3.1 → 4.0.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 (40) hide show
  1. package/README.md +32 -14
  2. package/dist/Epigraph/epigraph.d.ts +2 -2
  3. package/dist/Epigraph/epigraph.js +114 -0
  4. package/dist/EpigraphLibs/EpigraphAnalytics/epigraphAnalytics.js +69 -0
  5. package/dist/EpigraphLibs/EpigraphAnalytics/generics/queue.d.ts +3 -2
  6. package/dist/EpigraphLibs/EpigraphAnalytics/types/index.d.ts +7 -0
  7. package/dist/EpigraphLibs/EpigraphLogger/epigraphLogger.d.ts +3 -4
  8. package/dist/EpigraphLibs/EpigraphLogger/epigraphLogger.js +199 -0
  9. package/dist/EpigraphLibs/EpigraphNexusApi/epigraphNexusApi.js +153 -0
  10. package/dist/EpigraphLibs/EpigraphQrCodeGenerator/epigraphQrCodeGenerator.js +69 -0
  11. package/dist/EpigraphLibs/EpigraphResultFactory/epigraphResultFactory.js +28 -0
  12. package/dist/EpigraphLibs/EpigraphUnitsConverter/epigraphUnitsConverter.js +67 -0
  13. package/dist/EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.d.ts +1 -1
  14. package/dist/EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.js +76 -0
  15. package/dist/epigraph-std-lib.d.ts +1 -3
  16. package/dist/epigraph-std-lib.js +0 -37462
  17. package/dist/lib/Epigraph/constants/enums.js +4 -0
  18. package/dist/lib/Epigraph/epigraphBaseSolution.js +70 -0
  19. package/dist/lib/EpigraphLibs/EpigraphAnalytics/consent-plugins/consent-plugin-names.js +4 -0
  20. package/dist/lib/EpigraphLibs/EpigraphAnalytics/consent-plugins/one-trust-consent-plugin.js +29 -0
  21. package/dist/lib/EpigraphLibs/EpigraphAnalytics/generics/node.js +22 -0
  22. package/dist/lib/EpigraphLibs/EpigraphAnalytics/generics/queue.js +23 -0
  23. package/dist/lib/EpigraphLibs/EpigraphAnalytics/generics/single-linked-list.js +30 -0
  24. package/dist/lib/EpigraphLibs/EpigraphAnalytics/plugins/ga3-analytics-plugin.js +87 -0
  25. package/dist/lib/EpigraphLibs/EpigraphAnalytics/plugins/ga4-analytics-plugin.js +121 -0
  26. package/dist/lib/EpigraphLibs/EpigraphAnalytics/plugins/nexus-analytics-plugin.js +45 -0
  27. package/dist/lib/EpigraphLibs/EpigraphUnitsConverter/conversions.js +26 -0
  28. package/dist/lib/EpigraphLibs/EpigraphUnitsConverter/enums.js +5 -0
  29. package/dist/node_modules/lit-html/async-directive.js +67 -0
  30. package/dist/node_modules/lit-html/directive-helpers.js +10 -0
  31. package/dist/node_modules/lit-html/directive.js +27 -0
  32. package/dist/node_modules/lit-html/directives/ref.js +40 -0
  33. package/dist/node_modules/lit-html/lit-html.js +225 -0
  34. package/dist/vite-env.d.ts +1 -0
  35. package/package.json +56 -24
  36. package/dist/EpigraphLibs/epigraphLibs.d.ts +0 -9
  37. package/dist/ThirdPartyLibs/thirdPartyLibs.d.ts +0 -15
  38. package/dist/ThirdPartyLibs/three-gltf-extensions/exporters/KHR_materials_variants/KHR_materials_variants_exporter.d.ts +0 -9
  39. package/dist/ThirdPartyLibs/three-gltf-extensions/loaders/KHR_materials_variants/KHR_materials_variants.d.ts +0 -6
  40. /package/dist/EpigraphLibs/EpigraphAnalytics/{EpigraphAnalytics.d.ts → epigraphAnalytics.d.ts} +0 -0
package/README.md CHANGED
@@ -13,18 +13,8 @@ A global object that must only be initialized once per session and provides some
13
13
  | EpigraphBaseSolutionLitElement | A base class intended to enforce some common functionalities across our solutions, built by extending the LitElement |
14
14
  | EpigraphLogger | A logger class that provides a convenient way for logging info, warning or errors in any given session |
15
15
  | EpigraphQrCoreGenerator | A Utility class that allows the generation of a QR code from a give string input |
16
- | EpigraphUnitsConverter | A Utility class that allows conversion between different standard unit, including but not limited to Distance, Color, etc. |
17
- | EpigraphUrlProcessor | A Utility class that provides various methods to generate, process, manipulate URLs |
18
-
19
-
20
- ### 3rd PARTY LIBRARY EXPORTS
21
-
22
- | Name | Version |
23
- |---|---|
24
- | [three](https://threejs.org/) | ![three version](https://img.shields.io/badge/three-0.169.0-green) |
25
- | [model-viewer](https://modelviewer.dev/) | ![@google/model-viewer version](https://img.shields.io/badge/model--viewer-4.0.0-green) |
26
- | [@epigraph/epigraph-analytics](https://www.npmjs.com/package/@epigraph/epigraph-analytics) |![@epigraph/epigraph-analytics version](https://img.shields.io/badge/epigraph--analytics-1.0.0-green)|
27
- | [qr-creator](https://www.npmjs.com/package/qr-creator) |![qr-creator version](https://img.shields.io/badge/qr--creator-1.0.0-green)|
16
+ | EpigraphUnitsConverter | |
17
+ | EpigraphUrlProcessor | |
28
18
 
29
19
 
30
20
  # HOW TO:
@@ -32,8 +22,36 @@ A global object that must only be initialized once per session and provides some
32
22
  ### Add a new EpigraphLibrary:
33
23
  1. Create a new directory under lib/EpigraphLibs/`<MyEpigraphLibrary>`
34
24
  2. Create the module file/s. Ensure that the names of these files are in camelCase.
35
- 3. Export this module in lib/EpigraphLibs/epigraph-std-lib.ts as `export * from "./ThirdPartyLibs/main";`
36
- 4. Write a test for this Library under tests/<MyEpigraphLibrary.test.ts>
25
+ 3. Write a test for this Library under tests/<MyEpigraphLibrary.test.ts>
26
+ 4. Add the module that you wish to export as an entry in vite.config.ts > defineConfig > build > entry, similar to other entries in there. This will bundle the new module on build.
27
+ 5. Go to package.json:
28
+ - Add the new module entry under exports similar to other entries in that field.
29
+ - Add the new module entry under typesVersions similar to other entries in that field.
30
+
31
+ ### Use the library
32
+ This library exports the module into submodules to allow for better tree shaking when bundling the final product. Here is how you can import the submodules individually.
33
+
34
+ ```javascript
35
+ // Epigraph Object
36
+ import { Epigraph } from "@epigraph/epigraph-std-lib/dist/Epigraph/epigraph";
37
+
38
+ // Epigraph libs
39
+ import { EpigraphAnalytics } from "@epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics";
40
+
41
+ ```
42
+
43
+ Exported Submodules:
44
+ | Name | Description |
45
+ |---|---|
46
+ | @epigraph/epigraph-std-lib/dist/Epigraph/epigraph | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
47
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics | An Analytics modules that exports handy ways to log analytics across our solutions |
48
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphLogger | A Logger modules that exports handy ways to log across our solutions |
49
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphNexusApi | A Nexus API modules that exports handy ways to interact with the Nexus API across our solutions |
50
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphQrCodeGenerator | A QR Code generator modules that exports handy ways to generate QR Codes across our solutions |
51
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphResultFactory | A Result Factory modules that exports handy ways to generate Result objects across our solutions |
52
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUnitsConverter | A Utility class that allows conversion between different standard unit, including but not limited to Distance, Color, etc. |
53
+ | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUrlProcessor | A Utility class that provides various methods to generate, process, manipulate URLs |
54
+
37
55
 
38
56
  ### Write a test:
39
57
  We use [vitest](https://vitest.dev/guide/) to write tests in this repository using [happy-dom](https://www.npmjs.com/package/happy-dom) to support some but not all browser functionalities. In order to write a new test:
@@ -1,6 +1,6 @@
1
1
  import { EpigraphLogger, LoggerModeNames } from '../EpigraphLibs/EpigraphLogger/epigraphLogger';
2
2
  import { ENVIRONMENT_TYPE } from './constants/enums';
3
- import { UrlProcessor } from '../EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor';
3
+ import { EpigraphUrlProcessor } from '../EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor';
4
4
  import { EpigraphBaseSolutionTypes, EpigraphBaseSolutionHtmlElement, EpigraphBaseSolutionLitElement } from './epigraphBaseSolution';
5
5
  /**
6
6
  * Epigraph component is intended to be a global source of truth/tracker in a given session for all of our components.
@@ -24,7 +24,7 @@ export declare class Epigraph {
24
24
  constructor(initializer: EpigraphBaseSolutionTypes);
25
25
  get isReady(): boolean;
26
26
  get logger(): EpigraphLogger;
27
- get urlProcessor(): UrlProcessor;
27
+ get urlProcessor(): EpigraphUrlProcessor;
28
28
  get epigraphSessionId(): string;
29
29
  get environment(): ENVIRONMENT_TYPE;
30
30
  get initializer(): EpigraphBaseSolutionTypes;
@@ -0,0 +1,114 @@
1
+ import { EpigraphLogger as a, LoggerModeNames as r } from "../EpigraphLibs/EpigraphLogger/epigraphLogger.js";
2
+ import { ENVIRONMENT_TYPE as s } from "../lib/Epigraph/constants/enums.js";
3
+ import { EpigraphUrlProcessor as p, QUERY_PARAMETER_NAMES as l } from "../EpigraphLibs/EpigraphUrlProcessor/epigraphUrlProcessor.js";
4
+ import { EpigraphBaseSolutionHtmlElement as w, EpigraphBaseSolutionLitElement as I } from "../lib/Epigraph/epigraphBaseSolution.js";
5
+ class g {
6
+ constructor(e) {
7
+ if (this._loggerContext = "EPIGRAPH", this._isReady = !1, this._logger = new a("EPIGRAPH LOGGER"), this._environment = s.DEVELOPMENT, this._activeComponentsInSession = /* @__PURE__ */ new Map(), this._staleComponentsInSession = /* @__PURE__ */ new Map(), window.epigraph)
8
+ return window.epigraph.registerActiveComponent(e), window.epigraph;
9
+ window.epigraph = this, window.epigraph.registerActiveComponent(e), this.logBranding(), this._initializer = e, this._environment = this._initializer.environment;
10
+ const t = this.getLoggerModeNameFromEnvironment();
11
+ this._logger.setCurrentMode(t), this._urlProcessor = new p(), this.id = g.safeGenerateUuid();
12
+ const i = this._urlProcessor.getParameterInUrl(l.epigraphSessionId);
13
+ this._epigraphSessionId = i ?? g.safeGenerateUuid(), this._logger.info({ title: "Epigraph Object Ready!!", details: this, contextOverride: this._loggerContext }), this._isReady = !0;
14
+ }
15
+ get isReady() {
16
+ return this._isReady;
17
+ }
18
+ get logger() {
19
+ return this._logger;
20
+ }
21
+ get urlProcessor() {
22
+ return this._urlProcessor;
23
+ }
24
+ get epigraphSessionId() {
25
+ return this._epigraphSessionId;
26
+ }
27
+ get environment() {
28
+ return this._environment;
29
+ }
30
+ get initializer() {
31
+ return this._initializer;
32
+ }
33
+ get activeComponentsInSession() {
34
+ return this._activeComponentsInSession;
35
+ }
36
+ get staleComponentsInSession() {
37
+ return this._staleComponentsInSession;
38
+ }
39
+ /**
40
+ * Logs Epigraph Branding in the console to help redirect potential interests in the right direction.
41
+ */
42
+ logBranding() {
43
+ console.group("Powered by: "), console.log("%cEPIGRAPH", "font-weight: bold; font-size: 50px; text-shadow: 3px 3px 0 rgb(100,100,100)"), console.log("Visit for more details: www.epigraph.us"), console.groupEnd();
44
+ }
45
+ /**
46
+ * Registers a new component that was initialized on this page.
47
+ * This is optional from the perspective of the initialization flow but highly recommend
48
+ * registering any component that gets initialized in this session.
49
+ * Any component that inherits from EpigraphBaseSolution should automatically register itself on initialization.
50
+ *
51
+ * @param {EpigraphBaseSolutionTypes} solutionRef A type of Epigraph base component that is initialized in the session.
52
+ */
53
+ registerActiveComponent(e) {
54
+ this._activeComponentsInSession.set(e.uuid, e), this._logger.info({ title: "Registered a new Active Component", details: e, contextOverride: this._loggerContext });
55
+ }
56
+ /**
57
+ * De-Registers a component that was initialized on this page.
58
+ * This is optional from the perspective of the unmount flow but highly recommend
59
+ * de-registering any component that gets removed in this session.
60
+ * Any component that inherits from EpigraphBaseSolution should automatically de-register itself on unmount.
61
+ *
62
+ * @param {EpigraphBaseSolutionTypes} solutionRef A type of Epigraph base component that is initialized in the session.
63
+ */
64
+ deregisterActiveComponent(e) {
65
+ const t = this._activeComponentsInSession.get(e.uuid);
66
+ t && (this._staleComponentsInSession.set(t.uuid, t), this._activeComponentsInSession.delete(t.uuid), this._logger.info({ title: "Deregistered a new Active Component", details: e, contextOverride: this._loggerContext }));
67
+ }
68
+ /**
69
+ * Gets the mode that the logger should be executed in, based on the runtime environment.
70
+ *
71
+ * @returns {LoggerModeNames} A valid logger mode name.
72
+ */
73
+ getLoggerModeNameFromEnvironment() {
74
+ let e = r.Dev;
75
+ return this._environment === s.STAGING ? e = r.Staging : this._environment === s.PRODUCTION && (e = r.Release), e;
76
+ }
77
+ /**
78
+ * Generates a random UUID using crypto.randomUUID with a fallback on custom generator,
79
+ * if the first option fails for any reason in an environment.1
80
+ *
81
+ * @returns {string} A random generated ID.
82
+ */
83
+ static safeGenerateUuid() {
84
+ let e = "";
85
+ try {
86
+ e = crypto.randomUUID();
87
+ } catch {
88
+ console.error("crypto not available. Not generating a UUID");
89
+ }
90
+ return e;
91
+ }
92
+ /**
93
+ * Generates an XPath based on a DOM nodes location on the page.
94
+ *
95
+ * @param {HTMLElement} element The element that we need the XPath for.
96
+ * @returns {string} The generated XPath.
97
+ */
98
+ static generateXPath(e) {
99
+ let t = "", i = e;
100
+ for (; i; ) {
101
+ let o = 1, n = i.previousSibling;
102
+ for (; n; )
103
+ n.nodeName === i.nodeName && o++, n = n.previousSibling;
104
+ t = `/${i.nodeName.toLowerCase() + (o > 1 ? `[${o}]` : "")}${t}`, i = i.parentNode;
105
+ }
106
+ return t;
107
+ }
108
+ }
109
+ export {
110
+ s as ENVIRONMENT_TYPE,
111
+ g as Epigraph,
112
+ w as EpigraphBaseSolutionHtmlElement,
113
+ I as EpigraphBaseSolutionLitElement
114
+ };
@@ -0,0 +1,69 @@
1
+ import { GA3AnalyticsPlugin as c } from "../../lib/EpigraphLibs/EpigraphAnalytics/plugins/ga3-analytics-plugin.js";
2
+ import { GA4AnalyticsPlugin as f } from "../../lib/EpigraphLibs/EpigraphAnalytics/plugins/ga4-analytics-plugin.js";
3
+ import { NexusAnalyticsPlugin as m } from "../../lib/EpigraphLibs/EpigraphAnalytics/plugins/nexus-analytics-plugin.js";
4
+ import { OneTrustConsentPlugin as e } from "../../lib/EpigraphLibs/EpigraphAnalytics/consent-plugins/one-trust-consent-plugin.js";
5
+ import { ConsentPluginNames as l } from "../../lib/EpigraphLibs/EpigraphAnalytics/consent-plugins/consent-plugin-names.js";
6
+ /**
7
+ * @license
8
+ * Copyright (c) 2023 Epigraph LLC. All Rights Reserved.
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the 'License');
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an 'AS IS' BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ var s;
23
+ const i = Symbol("analyticsPluginsMap");
24
+ s = i;
25
+ class a {
26
+ constructor(n, t) {
27
+ this[s] = /* @__PURE__ */ new Map(), this._consentPlugin = null, n && t && (this._consentPlugin = this.buildConsentPlugin(n, t));
28
+ }
29
+ /**
30
+ * Epigraph Analytics uses plugins to send events to multiple trackers at a time. You can create a customer tracker
31
+ * by implementing the IAnalyticsPlugin and then adding it via this function. This will also hold only a single
32
+ * instance of a plugin with a given Tracking Identifier.
33
+ *
34
+ * @param plugin
35
+ */
36
+ addEventPlugin(n) {
37
+ this[i].has(n.getUniquePluginIdentifier()) || (this[i].set(
38
+ n.getUniquePluginIdentifier(),
39
+ n
40
+ ), n.setupPlugin());
41
+ }
42
+ /**
43
+ * Send an Event to all plugins
44
+ *
45
+ * @param eventData
46
+ */
47
+ sendEvent(n) {
48
+ this[i].forEach((t) => {
49
+ t.sendEvent(n, this._consentPlugin);
50
+ });
51
+ }
52
+ /**
53
+ * Returns an IConsentPlugin if something is passed to it. Returns null if we can't find the plugin named.
54
+ * @param consentPluginName
55
+ * @param consentIdentifier
56
+ * @private
57
+ */
58
+ buildConsentPlugin(n, t) {
59
+ return n.toLowerCase() === l.OneTrust.toLowerCase() ? new e(t) : null;
60
+ }
61
+ }
62
+ export {
63
+ l as ConsentPluginNames,
64
+ a as EpigraphAnalytics,
65
+ c as GA3AnalyticsPlugin,
66
+ f as GA4AnalyticsPlugin,
67
+ m as NexusAnalyticsPlugin,
68
+ e as OneTrustConsentPlugin
69
+ };
@@ -1,4 +1,5 @@
1
1
  import { default as SLL } from './single-linked-list.js';
2
+ import { AnalyticsEvent } from '../analytics-event-interface.ts';
2
3
  declare const $queue: unique symbol;
3
4
  declare const $size: unique symbol;
4
5
  export default class Queue {
@@ -7,7 +8,7 @@ export default class Queue {
7
8
  constructor();
8
9
  get queue(): SLL;
9
10
  get size(): number;
10
- enqueue(data: any): void;
11
- dequeue(): any;
11
+ enqueue(data: AnalyticsEvent): void;
12
+ dequeue(): AnalyticsEvent;
12
13
  }
13
14
  export {};
@@ -0,0 +1,7 @@
1
+ export {};
2
+
3
+ declare global {
4
+ interface Window {
5
+ gtag?: any;
6
+ }
7
+ }
@@ -1,8 +1,8 @@
1
- interface LoggerMode {
1
+ export interface LoggerMode {
2
2
  name: string;
3
3
  allows: Array<string>;
4
4
  }
5
- interface LoggerModes {
5
+ export interface LoggerModes {
6
6
  release: LoggerMode;
7
7
  staging: LoggerMode;
8
8
  dev: LoggerMode;
@@ -51,7 +51,7 @@ export interface ILoggerGroup {
51
51
  * Mode: A logger's mode defines what log types would be automatically executed and
52
52
  * what would be ignored.
53
53
  */
54
- declare class EpigraphLogger {
54
+ export declare class EpigraphLogger {
55
55
  context: string;
56
56
  private _allModes;
57
57
  private _currentMode;
@@ -153,4 +153,3 @@ declare class EpigraphLogger {
153
153
  */
154
154
  groupEnd(): void;
155
155
  }
156
- export { EpigraphLogger };
@@ -0,0 +1,199 @@
1
+ var t = /* @__PURE__ */ ((l) => (l.Release = "release", l.Staging = "staging", l.Dev = "dev", l))(t || {}), c = /* @__PURE__ */ ((l) => (l.Info = "info", l.Warn = "warn", l.Error = "error", l))(c || {});
2
+ class a {
3
+ /**
4
+ * @param {string} [context="EPIGRAPH-LOGGER"] Used to categorise each message within
5
+ * the console.
6
+ * @example,CORE, UI
7
+ */
8
+ constructor(o) {
9
+ this.context = "EPIGRAPH-LOGGER", this._allModes = {
10
+ release: { name: "release", allows: [
11
+ "error"
12
+ /* Error */
13
+ ] },
14
+ staging: {
15
+ name: "staging",
16
+ allows: [
17
+ "warn",
18
+ "error"
19
+ /* Error */
20
+ ]
21
+ },
22
+ dev: {
23
+ name: "dev",
24
+ allows: [
25
+ "info",
26
+ "warn",
27
+ "error"
28
+ /* Error */
29
+ ]
30
+ }
31
+ }, this._currentMode = "release", o && (this.context = o.toLocaleUpperCase());
32
+ }
33
+ get modes() {
34
+ return this._allModes;
35
+ }
36
+ /**
37
+ *
38
+ * @param {LoggerModeNames} newValue Sets the logger mode of the current instance.
39
+ */
40
+ setCurrentMode(o) {
41
+ if (!Object.keys(this._allModes).includes(o)) {
42
+ console.warn(`"${o}": is not a valid logger mode`);
43
+ return;
44
+ }
45
+ this._currentMode = o;
46
+ }
47
+ _isLogTypeAllowedInCurrentMode(o) {
48
+ return this._allModes[this._currentMode].allows.includes(o);
49
+ }
50
+ /**
51
+ * A log type that doesn't necessarily need to be looked at by the end user.
52
+ * This can be any generic log that would be ignored in most logger modes except verbose.
53
+ *
54
+ * @param {string} title A short title for this log.
55
+ * @param {any} details Any optional detail that would be shown if this log was expanded in the console.
56
+ * @param {string | undefined} contextOverride Allows the user to specify where this log
57
+ * was recorded from. For eg. Core and Ui can pass in different values for this
58
+ * paramater to make it easy to debug. If not provided, the default context would be used
59
+ * that was provided at the time of initialisation of this class.
60
+ */
61
+ info({ title: o, details: r = "", contextOverride: e = void 0 }) {
62
+ if (!this._isLogTypeAllowedInCurrentMode(
63
+ "info"
64
+ /* Info */
65
+ ))
66
+ return;
67
+ const n = e || this.context;
68
+ console.groupCollapsed(`[${n}]: ${o}`), console.log(r), console.groupCollapsed("Traceback..."), console.trace(), console.groupEnd(), console.groupEnd();
69
+ }
70
+ /**
71
+ * A warning log type that let's the user know that some action that could be dangerous was just
72
+ * performed and might need attention.
73
+ *
74
+ * @param {string} title A short title for this log.
75
+ * @param {any} details Any optional detail that would be shown if this log was expanded in the console.
76
+ * @param {string | undefined} contextOverride Allows the user to specify where this log
77
+ * was recorded from. For eg. Core and Ui can pass in different values for this
78
+ * paramater to make it easy to debug. If not provided, the default context would be used
79
+ * that was provided at the time of initialisation of this class.
80
+ */
81
+ warn({ title: o, details: r = "", contextOverride: e = void 0 }) {
82
+ if (!this._isLogTypeAllowedInCurrentMode(
83
+ "warn"
84
+ /* Warn */
85
+ ))
86
+ return;
87
+ const n = e || this.context;
88
+ console.groupCollapsed(`%c[${n}]: ${o}`, "color: orange;"), console.warn(r), console.groupCollapsed("Traceback..."), console.trace(), console.groupEnd(), console.groupEnd();
89
+ }
90
+ /**
91
+ * A critical error log type that let's the user know that some action that was unexpected and required immediate attention.
92
+ *
93
+ * @param {string} title A short title for this log.
94
+ * @param {any} details Any optional detail that would be shown if this log was expanded in the console.
95
+ * @param {string | undefined} contextOverride Allows the user to specify where this log
96
+ * was recorded from. For eg. Core and Ui can pass in different values for this
97
+ * paramater to make it easy to debug. If not provided, the default context would be used
98
+ * that was provided at the time of initialisation of this class.
99
+ */
100
+ error({ title: o, details: r = "", contextOverride: e = void 0 }) {
101
+ if (!this._isLogTypeAllowedInCurrentMode(
102
+ "error"
103
+ /* Error */
104
+ ))
105
+ return;
106
+ const n = e || this.context;
107
+ console.groupCollapsed(`%c[${n}]: ${o}`, "color: red;"), console.error(r), console.groupCollapsed("Traceback..."), console.trace(), console.groupEnd(), console.groupEnd();
108
+ }
109
+ /**
110
+ * A table log type that can show an object in an organised manner within the console.
111
+ * This is primarily for the visual purposes and doesn't provide any additional functionality
112
+ * that other log types cannot provide.
113
+ *
114
+ * @param {string} title A short title for this log.
115
+ * @param {any} details Any optional detail that would be shown if this log was expanded in the console.
116
+ * @param {string | undefined} contextOverride Allows the user to specify where this log
117
+ * was recorded from. For eg. Core and Ui can pass in different values for this
118
+ * paramater to make it easy to debug. If not provided, the default context would be used
119
+ * that was provided at the time of initialisation of this class.
120
+ * @param {LogTypes} logType A
121
+ */
122
+ table({
123
+ title: o,
124
+ details: r = {},
125
+ contextOverride: e = void 0,
126
+ logType: n = "info"
127
+ /* Info */
128
+ }) {
129
+ if (!this._isLogTypeAllowedInCurrentMode(n))
130
+ return;
131
+ const s = e || this.context;
132
+ console.groupCollapsed(`[${s}]: ${o}`), console.table(r), console.groupCollapsed("Traceback..."), console.trace(), console.groupEnd(), console.groupEnd();
133
+ }
134
+ /**
135
+ * Begins an expanded group with the browser's console window.
136
+ * NOTE: Please remember to close this group once done using EpigraphLogger.groupEnd();
137
+ *
138
+ * @param {string} title A short title for this group.
139
+ * @param {string | undefined} contextOverride Allows the user to specify where this log
140
+ * was recorded from. For eg. Core and Ui can pass in different values for this
141
+ * paramater to make it easy to debug. If not provided, the default context would be used
142
+ * that was provided at the time of initialisation of this class.
143
+ * @param {LogTypes} logType A group can implictly of any log type, by default it is of type
144
+ * info but this parameter allows the user to override this.
145
+ * @returns {void}
146
+ */
147
+ group({
148
+ title: o,
149
+ contextOverride: r = void 0,
150
+ logType: e = "info"
151
+ /* Info */
152
+ }) {
153
+ if (!this._isLogTypeAllowedInCurrentMode(e))
154
+ return;
155
+ const n = r || this.context;
156
+ console.group(`%c ${n} GROUP`, o);
157
+ }
158
+ /**
159
+ * Begins a collapsed group with the browser's console window.
160
+ * NOTE: Please remember to close this group once done using EpigraphLogger.groupEnd();
161
+ *
162
+ * @param {string} title A short title for this group.
163
+ * @param {string | undefined} contextOverride Allows the user to specify where this log
164
+ * was recorded from. For eg. Core and Ui can pass in different values for this
165
+ * paramater to make it easy to debug. If not provided, the default context would be used
166
+ * that was provided at the time of initialisation of this class.
167
+ * @param {LogTypes} logType A group can implictly of any log type, by default it is of type
168
+ * info but this parameter allows the user to override this.
169
+ * @returns {void}
170
+ */
171
+ groupCollapsed({
172
+ title: o,
173
+ contextOverride: r = void 0,
174
+ logType: e = "info"
175
+ /* Info */
176
+ }) {
177
+ if (!this._isLogTypeAllowedInCurrentMode(e))
178
+ return;
179
+ const n = r || this.context;
180
+ console.groupCollapsed(`%c ${n} GROUP`, o);
181
+ }
182
+ /**
183
+ * Similar to the console.groupEnd(). Useful for ending either a group or
184
+ * groupCollapse that was initialised by this logger.
185
+ *
186
+ * @returns {void}
187
+ */
188
+ groupEnd() {
189
+ this._isLogTypeAllowedInCurrentMode(
190
+ "info"
191
+ /* Info */
192
+ ) && (console.log("----------------------------------"), console.groupEnd());
193
+ }
194
+ }
195
+ export {
196
+ a as EpigraphLogger,
197
+ c as LogTypes,
198
+ t as LoggerModeNames
199
+ };
@@ -0,0 +1,153 @@
1
+ import { failureResult as p, successResult as u } from "../EpigraphResultFactory/epigraphResultFactory.js";
2
+ class x {
3
+ /**
4
+ * Constructs a new instance of the class with the provided parameters.
5
+ *
6
+ * @param {NexusEndpoints} [baseUrl=NexusEndpoints.PRODUCTION] - The base URL endpoint for the API, defaulting to the production environment.
7
+ * @param {string} epgLocation - The window.location.href associated with the epigraph data.
8
+ * @param {string} epigraphSessionId - The session identifier for the epigraph session.
9
+ * @param {string} epigraphComponentVersion - The version of the Epigraph Component(1.x.x or 1.2.1, etc.).
10
+ * @param {string} [epigraphXPath=""] - The XPath expression for epigraph data processing, defaults to an empty string.
11
+ * @param {NexusAPIVersions} [apiVersion=NexusAPIVersions.V1] - The API version to use, defaulting to version 1.
12
+ * @return {void}
13
+ */
14
+ constructor(e = "https://api.myepigraph.com/api/", i, r, s = "", n = "", a = "v1/") {
15
+ this.epigraphXPath = "", this.epigraphComponentVersion = s, this.epigraphSessionId = r, this.epigraphXPath = n, this.baseUrl = e + a, this.epgLocation = i;
16
+ }
17
+ /*******************************************************************************************************************
18
+ * Configurator API Calls *
19
+ ******************************************************************************************************************/
20
+ async getConfiguratorByExperienceId(e, i = "") {
21
+ const r = {};
22
+ i !== "" && (r.version_id = i);
23
+ const s = `experience/configurator/experience_id/${e}`, n = this.buildNexusUrl(
24
+ s,
25
+ r
26
+ );
27
+ return await this.callNexusAPI(
28
+ n,
29
+ "GET"
30
+ /* GET */
31
+ );
32
+ }
33
+ async getConfiguratorByClientAccessKey(e, i = "") {
34
+ const r = {};
35
+ i !== "" && (r.version_id = i);
36
+ const s = `experience/configurator/client_access_key/${e}`, n = this.buildNexusUrl(
37
+ s,
38
+ r
39
+ );
40
+ return await this.callNexusAPI(
41
+ n,
42
+ "GET"
43
+ /* GET */
44
+ );
45
+ }
46
+ /*******************************************************************************************************************
47
+ * ConfiguratorLite API Calls *
48
+ ******************************************************************************************************************/
49
+ async getConfiguratorLiteByExperienceId(e, i = "") {
50
+ const r = {};
51
+ i !== "" && (r.version_id = i);
52
+ const s = `experience/configurator-lite/experience_id/${e}`, n = this.buildNexusUrl(
53
+ s,
54
+ r
55
+ );
56
+ return await this.callNexusAPI(
57
+ n,
58
+ "GET"
59
+ /* GET */
60
+ );
61
+ }
62
+ async getConfiguratorLiteByProjectId(e, i = "") {
63
+ const r = {};
64
+ i !== "" && (r.version_id = i);
65
+ const s = `experience/configurator-lite/project_id/${e}`, n = this.buildNexusUrl(
66
+ s,
67
+ r
68
+ );
69
+ return await this.callNexusAPI(
70
+ n,
71
+ "GET"
72
+ /* GET */
73
+ );
74
+ }
75
+ /*******************************************************************************************************************
76
+ * Save & Share Calls *
77
+ ******************************************************************************************************************/
78
+ async postExperienceSaveAndShare(e, i) {
79
+ const r = "experience/" + e + "/save/", s = this.buildNexusUrl(
80
+ r
81
+ ), n = {
82
+ save_data: JSON.stringify(i)
83
+ }, a = new Headers();
84
+ return a.set("Content-Type", "application/json"), await this.callNexusAPI(s, "POST", JSON.stringify(n), a);
85
+ }
86
+ async getExperienceSaveAndShare(e, i) {
87
+ const r = "experience/" + e + "/save/" + i, s = this.buildNexusUrl(
88
+ r
89
+ );
90
+ return await this.callNexusAPI(
91
+ s,
92
+ "GET"
93
+ /* GET */
94
+ );
95
+ }
96
+ /**
97
+ * Makes a call to the Nexus API and ensures the response is returned in JSON format.
98
+ * Automatically appends the `application/json` accept header if not already provided.
99
+ *
100
+ * @param {URL} url - The URL of the Nexus API endpoint to call.
101
+ * @param method
102
+ * @param body
103
+ * @param headers
104
+ * @return {Promise<Result>} A promise that resolves with the API response, encapsulated in a success or failure result format.
105
+ */
106
+ async callNexusAPI(e, i = "GET", r, s = new Headers()) {
107
+ s = this.addRequiredHeaders(s);
108
+ const n = {
109
+ method: i,
110
+ body: r,
111
+ headers: s
112
+ };
113
+ try {
114
+ const a = await fetch(e, n), c = await a.json();
115
+ if (!a.ok) {
116
+ let o = "Unable to retrieve configurator experience";
117
+ return c.message && (o = c.message), Promise.resolve(
118
+ p(c, a.status, o)
119
+ );
120
+ }
121
+ return Promise.resolve(u(c, a.status));
122
+ } catch {
123
+ return Promise.resolve(p({}, 500, "Unknown error"));
124
+ }
125
+ }
126
+ buildNexusUrl(e, i = {}) {
127
+ let r = new URL(this.baseUrl);
128
+ r.pathname += e;
129
+ for (const [s, n] of Object.entries(i))
130
+ r.searchParams.set(s, n);
131
+ return r;
132
+ }
133
+ /**
134
+ * Adds required headers to the provided headers object if they are not already present.
135
+ * Ensures that the headers include "accept", "EPG-Location", "EPG-Session-ID",
136
+ * and "EPG-XPATH" with their respective values.
137
+ *
138
+ * @param {Headers} headers - The headers object to which the required headers will be added.
139
+ * @return {Headers} The updated headers object containing all required headers.
140
+ */
141
+ addRequiredHeaders(e) {
142
+ return e.has("accept") || e.set("accept", "application/json"), e.has("EPG-Location") || e.set("EPG-location", this.epgLocation), e.has("EPG-Session-ID") || e.set("EPG-Session-ID", this.epigraphSessionId), e.has("EPG-XPATH") || e.set("EPG-XPATH", this.epigraphXPath), e.has("EPG-Version") || e.set("EPG-Version", this.epigraphComponentVersion), e;
143
+ }
144
+ }
145
+ var l = /* @__PURE__ */ ((t) => (t.PRODUCTION = "https://api.myepigraph.com/api/", t.STAGING = "https://nexus.epigraph.dev/api/", t.LOCAL = "https://nexus.test/api/", t))(l || {}), h = /* @__PURE__ */ ((t) => (t.CLIENT_ACCESS_KEY = "client_access_key", t.EXPERIENCE_ID = "experience_id", t.PROJECT_ID = "project_id", t))(h || {}), E = /* @__PURE__ */ ((t) => (t.CONFIGURATOR = "experience/configurator/", t.CONFIGURATOR_LITE = "experience/configurator-lite/", t.EXPERIENCE = "experience/", t.SAVE = "save/", t))(E || {}), g = /* @__PURE__ */ ((t) => (t.V1 = "v1/", t))(g || {}), P = /* @__PURE__ */ ((t) => (t.GET = "GET", t.POST = "POST", t.PUT = "PUT", t.DELETE = "DELETE", t))(P || {});
146
+ export {
147
+ x as EpigraphNexusAPI,
148
+ P as HTTPMethod,
149
+ h as NexusAPIResourceIdentifier,
150
+ E as NexusAPIRoutes,
151
+ g as NexusAPIVersions,
152
+ l as NexusEndpoints
153
+ };