@matdata/yasr 5.14.0 → 5.16.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@matdata/yasr",
3
3
  "description": "Yet Another SPARQL Resultset GUI",
4
- "version": "5.14.0",
4
+ "version": "5.16.0",
5
5
  "main": "build/yasr.min.js",
6
6
  "types": "build/ts/src/index.d.ts",
7
7
  "license": "MIT",
package/src/index.ts CHANGED
@@ -601,6 +601,25 @@ export class Yasr extends EventEmitter {
601
601
  this.storeResponse();
602
602
  }
603
603
 
604
+ /**
605
+ * Execute a background SPARQL query from within a plugin.
606
+ *
607
+ * This delegates to the `executeQuery` callback supplied in the Yasr
608
+ * configuration (typically wired up by the Yasgui `Tab`). The raw
609
+ * response is returned so the calling plugin can process it without
610
+ * replacing the current result display.
611
+ *
612
+ * @param query The SPARQL query string to execute.
613
+ * @param options Optional execution options (e.g. a custom Accept header).
614
+ * @returns A Promise that resolves to the raw query response.
615
+ */
616
+ public executeQuery(query: string, options?: PluginQueryOptions): Promise<any> {
617
+ if (this.config.executeQuery) {
618
+ return this.config.executeQuery(query, options);
619
+ }
620
+ return Promise.reject(new Error("No executeQuery handler configured on this Yasr instance"));
621
+ }
622
+
604
623
  private initializePlugins() {
605
624
  for (const plugin in this.config.plugins) {
606
625
  if (!this.config.plugins[plugin]) continue; //falsy value, so assuming it should be disabled
@@ -635,6 +654,15 @@ export class Yasr extends EventEmitter {
635
654
  }
636
655
 
637
656
  export type Prefixes = { [prefixLabel: string]: string };
657
+
658
+ /**
659
+ * Options for executing a background query from a plugin.
660
+ */
661
+ export interface PluginQueryOptions {
662
+ /** Optional custom Accept header for the request (e.g. "text/turtle"). */
663
+ acceptHeader?: string;
664
+ }
665
+
638
666
  export interface PluginConfig {
639
667
  dynamicConfig?: any;
640
668
  staticConfig?: any;
@@ -660,6 +688,18 @@ export interface Config {
660
688
  * overwrite or explicitly call previously added or default ones.
661
689
  */
662
690
  errorRenderers?: ((error: Parser.ErrorSummary) => Promise<HTMLElement | undefined>)[];
691
+
692
+ /**
693
+ * Optional callback that allows plugins to execute a background SPARQL query.
694
+ * When set (e.g. by the Yasgui Tab), plugins can call `yasr.executeQuery(queryString)`
695
+ * to run an arbitrary query and receive the raw response, independently of the
696
+ * main query editor.
697
+ *
698
+ * @param query The SPARQL query string to execute.
699
+ * @param options Optional execution options (e.g. a custom Accept header).
700
+ * @returns A Promise that resolves to the raw query response.
701
+ */
702
+ executeQuery?: (query: string, options?: PluginQueryOptions) => Promise<any>;
663
703
  }
664
704
 
665
705
  export function registerPlugin(name: string, plugin: typeof Plugin, enable = true) {
@@ -102,6 +102,11 @@ export default class Error implements Plugin<never> {
102
102
  forbidden3.textContent = "Contact the endpoint administrator to request access";
103
103
  suggestions.appendChild(forbidden3);
104
104
 
105
+ const forbidden4 = document.createElement("li");
106
+ forbidden4.textContent =
107
+ "A firewall such as OWASP is blocking is blocking SPARQL queries because they resemble SQL injection attempts. Contact the endpoint administrator to whitelist your queries or adjust firewall settings";
108
+ suggestions.appendChild(forbidden4);
109
+
105
110
  guidanceEl.appendChild(suggestions);
106
111
  return guidanceEl;
107
112