@wiris/mathtype-viewer 8.9.2 → 8.10.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.
@@ -1 +1 @@
1
- /*! @license DOMPurify 3.1.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.3/LICENSE */
1
+ /*! @license DOMPurify 3.1.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.5/LICENSE */
@@ -1 +1 @@
1
- {"version":3,"file":"latex.d.ts","sourceRoot":"","sources":["../src/latex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY1C,wBAAsB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,iBAU1E"}
1
+ {"version":3,"file":"latex.d.ts","sourceRoot":"","sources":["../src/latex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY1C,wBAAsB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,iBAS1E"}
@@ -1,26 +1,27 @@
1
1
  type Viewer = "none" | "image" | "mathml" | "latex";
2
2
  type Wirispluginperformance = "true" | "false";
3
- export type Config = {
4
- editorServicesRoot?: string;
5
- editorServicesExtension?: string;
6
- backendConfig?: {
7
- wirispluginperformance?: Wirispluginperformance;
8
- wiriseditormathmlattribute?: string;
9
- wiriscustomheaders?: object;
3
+ export interface Config {
4
+ editorServicesRoot: string;
5
+ editorServicesExtension: string;
6
+ backendConfig: {
7
+ wirispluginperformance: Wirispluginperformance;
8
+ wiriseditormathmlattribute: string;
9
+ wiriscustomheaders: object;
10
10
  };
11
- dpi?: number;
12
- element?: string;
13
- lang?: string;
14
- viewer?: Viewer;
15
- zoom?: number;
16
- };
11
+ dpi: number;
12
+ element: string;
13
+ lang: string;
14
+ viewer: Viewer;
15
+ zoom: number;
16
+ }
17
17
  export declare class Properties {
18
18
  private static instance;
19
19
  render: () => Promise<void>;
20
20
  config: Config;
21
- private new;
22
- static getInstance(): Properties;
21
+ private constructor();
22
+ static getInstance(): Promise<Properties>;
23
23
  private initialize;
24
+ private setProperties;
24
25
  private checkServices;
25
26
  get editorServicesRoot(): string;
26
27
  set editorServicesRoot(editorServicesRoot: string);
@@ -1 +1 @@
1
- {"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../src/properties.ts"],"names":[],"mappings":"AAIA,KAAK,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AACpD,KAAK,sBAAsB,GAAG,MAAM,GAAG,OAAO,CAAC;AAK/C,MAAM,MAAM,MAAM,GAAG;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE;QACd,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;QAChD,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,CAAC;IACF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAuBF,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2B;IAElD,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAkB;IAG7C,MAAM,EAAE,MAAM,CAAiB;IAM/B,OAAO,CAAC,GAAG;IAEX,MAAM,CAAC,WAAW,IAAI,UAAU;YAWlB,UAAU;IAuDxB,OAAO,CAAC,aAAa;IAcrB,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,IAAI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ml: string, lang: string, url: string, extension: string): Promise<any>;
12
12
  export declare function createImage(mml: string, lang: string, url: string, extension: string): Promise<any>;
13
13
  export declare function latexToMathml(latex: string, url: string, extension: string): Promise<any>;
14
- export declare function configurationJson(variablekeys: string[], url: string, extension: string): Promise<any>;
14
+ export declare function configurationJson(variablekeys: string[], url: string, extension: string, check: boolean): Promise<any>;
15
15
  export {};
16
16
  //# sourceMappingURL=services.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAGA,aAAK,UAAU;IACb,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAKD,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,KAAA;CAIpB;AAUD,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAanF;AAUD,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,GAAG,CAAC,CA8Bd;AAUD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAa/G;AAUD,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAwBvG;AAUD,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAWzG;AASD,wBAAsB,aAAa,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GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAQ/F;AAQD,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EAAE,EACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,GAAG,CAAC,CAad"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiris/mathtype-viewer",
3
- "version": "8.9.2",
3
+ "version": "8.10.0",
4
4
  "description": "",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "author": "Integrations",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@wiris/mathtype-html-integration-devkit": "1.17.2"
19
+ "@wiris/mathtype-html-integration-devkit": "1.17.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/preset-typescript": "^7.24.1",
package/src/app.ts CHANGED
@@ -48,7 +48,7 @@ async function main(w: Window): Promise<void> {
48
48
  * @param {MutationObserver} observer - Mutation observer to activate or reactivate every time the rendering root changes.
49
49
  */
50
50
  properties.render = async () => {
51
- const element: HTMLElement = document.querySelector(properties.element);
51
+ const element: HTMLElement | null = document.querySelector(properties.element);
52
52
  if (element) {
53
53
  await renderLatex(properties, element);
54
54
  await renderMathML(properties, element);
package/src/latex.ts CHANGED
@@ -15,7 +15,6 @@ export async function renderLatex(properties: Properties, root: HTMLElement) {
15
15
  if (properties.viewer !== "image" && properties.viewer !== "latex") {
16
16
  return;
17
17
  }
18
-
19
18
  const latexNodes = findLatexTextNodes(root);
20
19
 
21
20
  for (const latexNode of latexNodes) {
@@ -29,18 +28,18 @@ export async function renderLatex(properties: Properties, root: HTMLElement) {
29
28
  * @param {Node} node - Text node in which to search and replace LaTeX instances.
30
29
  */
31
30
  async function replaceLatexInTextNode(properties: Properties, node: Node) {
32
- const textContent: string = node.textContent || "";
31
+ const textContent: string = node.textContent ?? "";
33
32
  let pos: number = 0;
34
33
 
35
34
  while (pos < textContent.length) {
36
- const nextLatexPosition: LatexPosition = getNextLatexPos(pos, textContent);
35
+ const nextLatexPosition = getNextLatexPos(pos, textContent);
37
36
  if (nextLatexPosition) {
38
37
  // Get left non LaTeX text.
39
38
  const leftText: string = textContent.substring(pos, nextLatexPosition.start);
40
39
  const leftTextNode = document.createTextNode(leftText);
41
40
  // Create a node with left text.
42
41
  node.parentNode?.insertBefore(leftTextNode, node);
43
- node.nodeValue = node.nodeValue.substring(pos, nextLatexPosition.start);
42
+ node.nodeValue = node.nodeValue?.substring(pos, nextLatexPosition.start) ?? "";
44
43
 
45
44
  // Get LaTeX text.
46
45
  const latex = textContent.substring(nextLatexPosition.start + "$$".length, nextLatexPosition.end);
@@ -92,7 +91,7 @@ function findLatexTextNodes(root: any): Node[] {
92
91
  * @param {string} text - Text where the next latex it will be searched.
93
92
  * @
94
93
  */
95
- function getNextLatexPos(pos: number, text: string): LatexPosition {
94
+ function getNextLatexPos(pos: number, text: string): LatexPosition | null {
96
95
  const firstLatexTags = text.indexOf("$$", pos);
97
96
  const secondLatexTags = firstLatexTags == -1 ? -1 : text.indexOf("$$", firstLatexTags + "$$".length);
98
97
  return firstLatexTags != -1 && secondLatexTags != -1 ? { start: firstLatexTags, end: secondLatexTags } : null;
package/src/properties.ts CHANGED
@@ -8,20 +8,20 @@ type Wirispluginperformance = "true" | "false";
8
8
  /**
9
9
  * Type representing all the configuration for the viewer.
10
10
  */
11
- export type Config = {
12
- editorServicesRoot?: string;
13
- editorServicesExtension?: string;
14
- backendConfig?: {
15
- wirispluginperformance?: Wirispluginperformance;
16
- wiriseditormathmlattribute?: string;
17
- wiriscustomheaders?: object;
11
+ export interface Config {
12
+ editorServicesRoot: string;
13
+ editorServicesExtension: string;
14
+ backendConfig: {
15
+ wirispluginperformance: Wirispluginperformance;
16
+ wiriseditormathmlattribute: string;
17
+ wiriscustomheaders: object;
18
18
  };
19
- dpi?: number;
20
- element?: string;
21
- lang?: string;
22
- viewer?: Viewer;
23
- zoom?: number;
24
- };
19
+ dpi: number;
20
+ element: string;
21
+ lang: string;
22
+ viewer: Viewer;
23
+ zoom: number;
24
+ }
25
25
 
26
26
  /**
27
27
  * Fallback values for the configurations that are not set.
@@ -53,15 +53,15 @@ export class Properties {
53
53
  config: Config = defaultValues;
54
54
 
55
55
  /**
56
- * Do not use this method. Instead, use {@link Properties.generate}.
57
- * Constructors cannot be async so we make it private and force instantiation through an alternative static method.
56
+ * Private constructor to avoid multiple instances of the class.
57
+ * To instantiate the class, use the static method {@link Properties.getInstance}.
58
58
  */
59
- private new() {}
59
+ private constructor() {}
60
60
 
61
- static getInstance(): Properties {
61
+ static async getInstance(): Promise<Properties> {
62
62
  if (!Properties.instance) {
63
63
  Properties.instance = new Properties();
64
- Properties.instance.initialize();
64
+ await Properties.instance.initialize();
65
65
  }
66
66
  return Properties.instance;
67
67
  }
@@ -70,33 +70,20 @@ export class Properties {
70
70
  * Creates and sets up a new instance of class Properties
71
71
  */
72
72
  private async initialize(): Promise<void> {
73
+ if (!Properties.instance) {
74
+ console.error("Properties.instance is not set");
75
+ return;
76
+ }
73
77
  // Get URL parameters from <script>
74
78
  const pluginName = "WIRISplugins.js";
75
- const script: HTMLScriptElement = document.querySelector(`script[src*="${pluginName}"]`);
76
-
77
- if (!!script) {
78
- const pluginNamePosition: number = script.src.lastIndexOf(pluginName);
79
- const params: string = script.src.substring(pluginNamePosition + pluginName.length);
80
- const urlParams = new URLSearchParams(params);
79
+ const script: HTMLScriptElement | null = document.querySelector(`script[src*="${pluginName}"]`);
81
80
 
82
- if (urlParams.get("dpi") !== null && urlParams.get("dpi") !== undefined) {
83
- Properties.instance.config.dpi = +urlParams.get("dpi");
84
- }
85
- if (urlParams.get("element") !== null && urlParams.get("element") !== undefined) {
86
- Properties.instance.config.element = urlParams.get("element");
87
- }
88
- if (urlParams.get("lang") !== null && urlParams.get("lang") !== undefined) {
89
- Properties.instance.config.lang = urlParams.get("lang");
90
- }
91
- if (urlParams.get("viewer") !== null && urlParams.get("viewer") !== undefined) {
92
- Properties.instance.config.viewer = urlParams.get("viewer") as Viewer;
93
- }
94
- if (urlParams.get("zoom") !== null && urlParams.get("zoom") !== undefined) {
95
- Properties.instance.config.zoom = +urlParams.get("zoom");
96
- }
81
+ // If the absence of the script is an error maybe this should throw
82
+ if (script) {
83
+ this.setProperties(script, pluginName, Properties.instance);
97
84
  }
98
85
 
99
- Properties.instance.checkServices();
86
+ await Properties.instance.checkServices();
100
87
 
101
88
  // Get backend parameters calling the configurationjson service
102
89
  try {
@@ -104,6 +91,7 @@ export class Properties {
104
91
  ["wirispluginperformance", "wiriseditormathmlattribute", "wiriscustomheaders"],
105
92
  Properties.instance.editorServicesRoot,
106
93
  Properties.instance.editorServicesExtension,
94
+ false,
107
95
  );
108
96
 
109
97
  // We'll always get a string from the wiriscustomheaders backend parameter. It needs to be converted to an object.
@@ -120,21 +108,68 @@ export class Properties {
120
108
  }
121
109
  }
122
110
 
111
+ /**
112
+ * Initialize properties from <script>
113
+ * @param script
114
+ * @param pluginName
115
+ * @param instance
116
+ */
117
+ private setProperties(script: HTMLScriptElement, pluginName: string, instance: Properties) {
118
+ const pluginNamePosition: number = script.src.lastIndexOf(pluginName);
119
+ const params: string = script.src.substring(pluginNamePosition + pluginName.length);
120
+ const urlParams = new URLSearchParams(params);
121
+
122
+ const dpi = urlParams.get("dpi");
123
+ if (dpi !== null && dpi !== undefined) {
124
+ instance.config.dpi = +dpi;
125
+ }
126
+
127
+ const element = urlParams.get("element");
128
+ if (element !== null && element !== undefined) {
129
+ instance.config.element = element;
130
+ }
131
+
132
+ const lang = urlParams.get("lang");
133
+ if (lang !== null && lang !== undefined) {
134
+ instance.config.lang = lang;
135
+ }
136
+
137
+ const viewer = urlParams.get("viewer");
138
+ if (viewer !== null && viewer !== undefined) {
139
+ instance.config.viewer = viewer as Viewer;
140
+ }
141
+
142
+ const zoom = urlParams.get("zoom");
143
+ if (zoom !== null && zoom !== undefined) {
144
+ instance.config.zoom = +zoom;
145
+ }
146
+ }
147
+
123
148
  /**
124
149
  * Check if is inside Integrations Services
125
150
  * @deprecated This will be removed once the viewer uncouple from the integration services.
126
151
  */
127
- private checkServices(): void {
152
+ private async checkServices() {
128
153
  const path = (document.currentScript as HTMLScriptElement).src;
129
154
 
130
- if (path.includes("pluginwiris_engine")) {
131
- // If the path includes pluginwiris_engine use Java Integrations Services
132
- this.config.editorServicesRoot = path;
133
- this.config.editorServicesExtension = "";
134
- } else if (path.includes("integration/WIRISplugins")) {
155
+ if (path.includes("integration/WIRISplugins")) {
135
156
  // If the path includes 'integration/WIRISplugins' use PHP Integrations Services
136
157
  this.config.editorServicesRoot = path;
137
158
  this.config.editorServicesExtension = ".php";
159
+ } else {
160
+ try {
161
+ // We want to know if we are using the integrations java services.
162
+ // So we call the configurationjson service assuming that the path is the one for the Java services.
163
+ // If we get an answer, we know we are using the Java services,
164
+ // otherwise, and since PHP has already been discarded, we'll set the services to wiris.net
165
+ await configurationJson(["wirispluginperformance"], path, "", true);
166
+
167
+ this.config.editorServicesRoot = path;
168
+ this.config.editorServicesExtension = "";
169
+ } catch (e) {
170
+ // We do noting.
171
+ // Getting here means that we are not using php nor Java services so we'll stick to the wiris.net default.
172
+ }
138
173
  }
139
174
  }
140
175
 
package/src/retro.ts CHANGED
@@ -29,6 +29,11 @@ export function bypassEncapsulation(properties: Properties, w: Window) {
29
29
  }
30
30
  }
31
31
 
32
+ interface MathMLPosition {
33
+ nextElement: Node;
34
+ safeMML: string;
35
+ }
36
+
32
37
  /**
33
38
  * This class is a compatibility layer with the old Viewer.
34
39
  * See haxe/src-haxe/com/wiris/js/JsPluginViewer.hx in in the repo wiris/plugins previous to commit df1248a.
@@ -58,12 +63,12 @@ class JsPluginViewer {
58
63
  * Please consider using {@link renderLatex} or {@link renderMathML}.
59
64
  */
60
65
  parseSafeMathMLElement(element: HTMLElement, asynchronously?: boolean, callbackFunc?: () => void): void {
61
- var mathmlPositions = [];
66
+ var mathmlPositions: MathMLPosition[] = [];
62
67
  JsPluginViewer.getMathMLPositionsAtElementAndChildren(element, mathmlPositions);
63
68
  for (let i = 0; i < mathmlPositions.length; i++) {
64
69
  var mathmlPosition = mathmlPositions[i];
65
70
  var newNode = document.createElement("math");
66
- mathmlPosition.nextElement.parentNode.insertBefore(newNode, mathmlPosition.nextElement);
71
+ mathmlPosition.nextElement.parentNode?.insertBefore(newNode, mathmlPosition.nextElement);
67
72
  newNode.outerHTML = JsPluginViewer.decodeSafeMathML(mathmlPosition.safeMML);
68
73
  }
69
74
  }
@@ -148,7 +153,7 @@ class JsPluginViewer {
148
153
  // We are replacing $ by & when its part of an entity for retrocompatibility.
149
154
  // Now, the standard is replace § by &.
150
155
  var returnValue = "";
151
- var currentEntity = null;
156
+ var currentEntity: string | null = null;
152
157
 
153
158
  var i = 0;
154
159
  while (i < inputCopy.length) {
@@ -176,7 +181,7 @@ class JsPluginViewer {
176
181
  return returnValue;
177
182
  }
178
183
 
179
- private static getMathMLPositionsAtElementAndChildren(element: Node, mathmlPositions) {
184
+ private static getMathMLPositionsAtElementAndChildren(element: Node, mathmlPositions: MathMLPosition[]) {
180
185
  JsPluginViewer.getMathMLPositionsAtNode(element, mathmlPositions);
181
186
  // Copy current children because DOM will be changed and element.childNodes won't be
182
187
  // consistent on call getMathMLPositionsAtElementAndChildren().
@@ -194,22 +199,23 @@ class JsPluginViewer {
194
199
  if (node.nodeType == 3) {
195
200
  var startMathmlTag = safeXMLCharacters.tagOpener + "math";
196
201
  var endMathmlTag = safeXMLCharacters.tagOpener + "/math" + safeXMLCharacters.tagCloser;
197
- var start = node.textContent.indexOf(startMathmlTag);
202
+ var start = node.textContent?.indexOf(startMathmlTag) ?? -1;
198
203
  var end = 0;
199
204
  while (start != -1) {
200
- end = node.textContent.indexOf(endMathmlTag, start + startMathmlTag.length);
205
+ end = node.textContent?.indexOf(endMathmlTag, start + startMathmlTag.length) ?? -1;
201
206
 
202
207
  if (end == -1) break;
203
208
 
204
- var nextMathML = node.textContent.indexOf(startMathmlTag, end + endMathmlTag.length);
209
+ var nextMathML = node.textContent?.indexOf(startMathmlTag, end + endMathmlTag.length) ?? -1;
205
210
 
206
211
  if (nextMathML >= 0 && end > nextMathML) break;
207
212
 
208
- var safeMathml = node.textContent.substring(start, end + endMathmlTag.length);
213
+ var safeMathml = node.textContent?.substring(start, end + endMathmlTag.length);
209
214
 
210
- node.textContent = node.textContent.substring(0, start) + node.textContent.substring(end + endMathmlTag.length);
215
+ node.textContent =
216
+ (node.textContent?.substring(0, start) ?? "") + node.textContent?.substring(end + endMathmlTag.length);
211
217
  node = (node as Text).splitText(start);
212
- start = node.textContent.indexOf(startMathmlTag);
218
+ start = node.textContent?.indexOf(startMathmlTag) ?? -1;
213
219
 
214
220
  mathmlPositions.push({
215
221
  safeMML: safeMathml,
package/src/services.ts CHANGED
@@ -57,7 +57,8 @@ export async function callService(
57
57
  try {
58
58
  const url = new URL(serviceName + extension, serverURL);
59
59
 
60
- const properties = Properties.getInstance();
60
+ // Getting the configuration is asynchronous since we make some requests.
61
+ const properties = await Properties.getInstance();
61
62
  const headers = {
62
63
  "Content-type": "application/x-www-form-urlencoded; charset=utf-8",
63
64
  ...properties.config.backendConfig.wiriscustomheaders,
@@ -186,11 +187,22 @@ export async function latexToMathml(latex: string, url: string, extension: strin
186
187
  * @param {string} extension - Extension to add to the end of the serviceName (including the dot if necessary).
187
188
  * @returns {Promise<Response>} The configurationjson service response.
188
189
  */
189
- export async function configurationJson(variablekeys: string[], url: string, extension: string): Promise<any> {
190
+ export async function configurationJson(
191
+ variablekeys: string[],
192
+ url: string,
193
+ extension: string,
194
+ check: boolean,
195
+ ): Promise<any> {
190
196
  const params = {
191
197
  variablekeys: variablekeys.join(","),
192
198
  };
193
199
 
194
- const response = callService(params, "configurationjson", MethodType.Get, url, extension);
200
+ const response = await callService(params, "configurationjson", MethodType.Get, url, extension);
201
+
202
+ // Provide a warning to alert the users that the console error is an expected outcome,
203
+ // since this request only aims to be a check and does not expect to retrieve any data.
204
+ if (check && !response.ok) {
205
+ console.warn("Fetching the url: " + response.url + ", is expected to fail and handled. Don't panic!");
206
+ }
195
207
  return processJsonResponse(response);
196
208
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "strict": true,
3
4
  /* Basic Options */
4
5
  "target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
5
6
  "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,