@matdata/yasqe 5.9.0 → 5.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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,202 @@
1
+ import { describe, it } from "mocha";
2
+ import { expect } from "chai";
3
+ describe("Share Functionality", () => {
4
+ describe("Shell String Escaping", () => {
5
+ it("should escape single quotes for shell commands", () => {
6
+ const input = "test'value";
7
+ const escaped = input.replace(/'/g, "'\\''");
8
+ expect(escaped).to.equal("test'\\''value");
9
+ });
10
+ it("should handle strings with multiple single quotes", () => {
11
+ const input = "it's a 'test'";
12
+ const escaped = input.replace(/'/g, "'\\''");
13
+ expect(escaped).to.equal("it'\\''s a '\\''test'\\''");
14
+ });
15
+ });
16
+ describe("PowerShell String Escaping", () => {
17
+ it("should escape backticks, double quotes, and dollar signs", () => {
18
+ const input = 'test"value$var`tick';
19
+ const escaped = input.replace(/`/g, "``").replace(/"/g, '`"').replace(/\$/g, "`$");
20
+ expect(escaped).to.equal('test`"value`$var``tick');
21
+ });
22
+ it("should handle strings with multiple special characters", () => {
23
+ const input = '$test`"value"';
24
+ const escaped = input.replace(/`/g, "``").replace(/"/g, '`"').replace(/\$/g, "`$");
25
+ expect(escaped).to.equal('`$test```"value`"');
26
+ });
27
+ });
28
+ describe("URL Normalization", () => {
29
+ it("should detect absolute URLs", () => {
30
+ const url = "https://example.com/sparql";
31
+ expect(url.indexOf("http")).to.equal(0);
32
+ });
33
+ it("should detect relative URLs", () => {
34
+ const url = "/sparql";
35
+ expect(url.indexOf("http")).to.equal(-1);
36
+ expect(url.indexOf("/")).to.equal(0);
37
+ });
38
+ it("should handle relative path normalization", () => {
39
+ const pathname = "/app/editor";
40
+ const relativePath = "sparql";
41
+ let basePath = pathname;
42
+ if (!basePath.endsWith("/")) {
43
+ const lastSlashIndex = basePath.lastIndexOf("/");
44
+ basePath = lastSlashIndex >= 0 ? basePath.substring(0, lastSlashIndex + 1) : "/";
45
+ }
46
+ const result = basePath + relativePath;
47
+ expect(result).to.equal("/app/sparql");
48
+ });
49
+ it("should handle pathname ending with slash", () => {
50
+ const pathname = "/app/";
51
+ const relativePath = "sparql";
52
+ let basePath = pathname;
53
+ if (!basePath.endsWith("/")) {
54
+ const lastSlashIndex = basePath.lastIndexOf("/");
55
+ basePath = lastSlashIndex >= 0 ? basePath.substring(0, lastSlashIndex + 1) : "/";
56
+ }
57
+ const result = basePath + relativePath;
58
+ expect(result).to.equal("/app/sparql");
59
+ });
60
+ });
61
+ describe("Command Generation Format", () => {
62
+ it("should format cURL commands with proper line breaks", () => {
63
+ const segments = [
64
+ "curl",
65
+ "'https://example.com/sparql'",
66
+ "--data",
67
+ "'query=SELECT'",
68
+ "-X",
69
+ "POST",
70
+ "-H",
71
+ "'Authorization: Bearer token'",
72
+ ];
73
+ const curlString = segments.join(" \\\n ");
74
+ expect(curlString).to.include("curl");
75
+ expect(curlString).to.include("\\\n");
76
+ expect(curlString).to.include("https://example.com/sparql");
77
+ });
78
+ it("should format PowerShell commands with proper structure", () => {
79
+ const lines = [
80
+ "$params = @{",
81
+ ' Uri = "https://example.com/sparql"',
82
+ ' Method = "Post"',
83
+ " Headers = @{",
84
+ ' "Accept" = "application/sparql-results+json"',
85
+ ' "Authorization" = "Bearer token"',
86
+ " }",
87
+ ' ContentType = "application/x-www-form-urlencoded"',
88
+ ' Body = "query=SELECT"',
89
+ ' OutFile = "result.json"',
90
+ "}",
91
+ "",
92
+ "Invoke-WebRequest @params",
93
+ ];
94
+ const psString = lines.join("\n");
95
+ expect(psString).to.include("$params");
96
+ expect(psString).to.include("Invoke-WebRequest");
97
+ expect(psString).to.include("Headers");
98
+ expect(psString).to.include("OutFile");
99
+ expect(psString).to.include("Accept");
100
+ });
101
+ it("should format wget commands with proper line breaks", () => {
102
+ const segments = [
103
+ "wget",
104
+ "'https://example.com/sparql'",
105
+ "--body-data",
106
+ "'query=SELECT'",
107
+ "--method",
108
+ "POST",
109
+ "--header",
110
+ "'Authorization: Bearer token'",
111
+ "-O -",
112
+ ];
113
+ const wgetString = segments.join(" \\\n ");
114
+ expect(wgetString).to.include("wget");
115
+ expect(wgetString).to.include("\\\n");
116
+ expect(wgetString).to.include("--body-data");
117
+ });
118
+ });
119
+ describe("URL Normalization", () => {
120
+ it("should handle absolute URLs", () => {
121
+ const url = "https://example.com/sparql";
122
+ expect(url.indexOf("http")).to.equal(0);
123
+ });
124
+ it("should detect relative URLs", () => {
125
+ const url = "/sparql";
126
+ expect(url.indexOf("http")).to.equal(-1);
127
+ expect(url.indexOf("/")).to.equal(0);
128
+ });
129
+ it("should detect relative paths", () => {
130
+ const url = "sparql";
131
+ expect(url.indexOf("http")).to.equal(-1);
132
+ expect(url.indexOf("/")).to.not.equal(0);
133
+ });
134
+ });
135
+ describe("Authentication Detection Logic", () => {
136
+ it("should detect Authorization header", () => {
137
+ const headers = { Authorization: "Bearer token" };
138
+ expect(headers["Authorization"]).to.exist;
139
+ });
140
+ it("should detect API key headers by name", () => {
141
+ const headerName = "X-API-Key";
142
+ const lowerHeader = headerName.toLowerCase();
143
+ expect(lowerHeader).to.include("key");
144
+ });
145
+ it("should detect token headers by name", () => {
146
+ const headerName = "X-Auth-Token";
147
+ const lowerHeader = headerName.toLowerCase();
148
+ expect(lowerHeader).to.include("token");
149
+ });
150
+ it("should detect auth headers by name", () => {
151
+ const headerName = "X-Custom-Auth";
152
+ const lowerHeader = headerName.toLowerCase();
153
+ expect(lowerHeader).to.include("auth");
154
+ });
155
+ it("should not detect non-auth headers", () => {
156
+ const headerName = "Content-Type";
157
+ const lowerHeader = headerName.toLowerCase();
158
+ expect(lowerHeader).to.not.include("key");
159
+ expect(lowerHeader).to.not.include("token");
160
+ expect(lowerHeader).to.not.include("auth");
161
+ });
162
+ });
163
+ describe("String Escaping", () => {
164
+ it("should escape double quotes in PowerShell", () => {
165
+ const value = 'test"value';
166
+ const escaped = value.replace(/"/g, '`"');
167
+ expect(escaped).to.equal('test`"value');
168
+ });
169
+ it("should handle single quotes in shell commands", () => {
170
+ const value = "test'value";
171
+ const wrapped = `'${value}'`;
172
+ expect(wrapped).to.equal("'test'value'");
173
+ });
174
+ });
175
+ describe("HTTP Method Handling", () => {
176
+ it("should use POST for SPARQL updates", () => {
177
+ const queryMode = "update";
178
+ const method = queryMode === "update" ? "POST" : "GET";
179
+ expect(method).to.equal("POST");
180
+ });
181
+ it("should default to configured method for SPARQL queries", () => {
182
+ const queryMode = "query";
183
+ const method = queryMode === "update" ? "POST" : "GET";
184
+ expect(method).to.equal("GET");
185
+ });
186
+ });
187
+ describe("Query String Formatting", () => {
188
+ it("should format query parameters", () => {
189
+ const params = { query: "SELECT * WHERE { ?s ?p ?o }", format: "json" };
190
+ const keys = Object.keys(params);
191
+ expect(keys).to.include("query");
192
+ expect(keys).to.include("format");
193
+ });
194
+ it("should handle URL encoding", () => {
195
+ const query = "SELECT * WHERE { ?s ?p ?o }";
196
+ const encoded = encodeURIComponent(query);
197
+ expect(encoded).to.include("SELECT");
198
+ expect(encoded).to.not.include(" ");
199
+ });
200
+ });
201
+ });
202
+ //# sourceMappingURL=share-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-test.js","sourceRoot":"","sources":["../../../../../../packages/yasqe/src/__tests__/share-test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,MAAM,KAAK,GAAG,YAAY,CAAC;YAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC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AC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACpC,MAAM,KAAK,GAAG,6BAA6B,CAAC;YAC5C,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC1C,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACrC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -122,6 +122,9 @@ export declare class Yasqe extends CodeMirror {
122
122
  configToQueryParams(): queryString.ParsedQuery;
123
123
  queryParamsToConfig(params: queryString.ParsedQuery): void;
124
124
  getAsCurlString(config?: Sparql.YasqeAjaxConfig): string;
125
+ getAsPowerShellString(config?: Sparql.YasqeAjaxConfig): string;
126
+ getAsWgetString(config?: Sparql.YasqeAjaxConfig): string;
127
+ hasAuthenticationCredentials(config?: Sparql.YasqeAjaxConfig): boolean;
125
128
  abortQuery(): void;
126
129
  expandEditor(): void;
127
130
  destroy(): void;
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import "./scss/yasqe.scss";
2
11
  import "./scss/buttons.scss";
3
12
  import { findFirstPrefixLine } from "./prefixFold";
@@ -14,6 +23,10 @@ import { mergeWith, escape } from "lodash-es";
14
23
  import getDefaults from "./defaults";
15
24
  import CodeMirror from "./CodeMirror";
16
25
  import { spfmt } from "sparql-formatter";
26
+ const TOAST_DEFAULT_DURATION = 3000;
27
+ const TOAST_WARNING_DURATION = 4000;
28
+ const TOAST_WARNING_DELAY = 500;
29
+ const TOAST_FADEOUT_DURATION = 300;
17
30
  export class Yasqe extends CodeMirror {
18
31
  constructor(parent, conf = {}) {
19
32
  super();
@@ -195,70 +208,174 @@ export class Yasqe extends CodeMirror {
195
208
  let popup = document.createElement("div");
196
209
  popup.className = "yasqe_sharePopup";
197
210
  buttons.appendChild(popup);
198
- document.body.addEventListener("click", (event) => {
211
+ let toastElement;
212
+ let toastTimeout;
213
+ const showToast = (message, duration = TOAST_DEFAULT_DURATION, type = "info") => {
214
+ if (toastElement) {
215
+ toastElement.remove();
216
+ }
217
+ if (toastTimeout !== undefined) {
218
+ clearTimeout(toastTimeout);
219
+ }
220
+ toastElement = document.createElement("div");
221
+ toastElement.className = type === "warning" ? "yasqe_toast yasqe_toast-warning" : "yasqe_toast";
222
+ if (type === "warning") {
223
+ const iconWrapper = document.createElement("span");
224
+ iconWrapper.className = "yasqe_toast-icon";
225
+ const icon = drawSvgStringAsElement(imgs.warning);
226
+ iconWrapper.appendChild(icon);
227
+ toastElement.appendChild(iconWrapper);
228
+ }
229
+ const messageSpan = document.createElement("span");
230
+ messageSpan.className = "yasqe_toast-message";
231
+ messageSpan.textContent = message;
232
+ toastElement.appendChild(messageSpan);
233
+ document.body.appendChild(toastElement);
234
+ toastTimeout = window.setTimeout(() => {
235
+ if (toastElement) {
236
+ toastElement.classList.add("yasqe_toast-fadeout");
237
+ setTimeout(() => {
238
+ toastElement === null || toastElement === void 0 ? void 0 : toastElement.remove();
239
+ toastElement = undefined;
240
+ }, TOAST_FADEOUT_DURATION);
241
+ }
242
+ }, duration);
243
+ };
244
+ const closePopupHandler = (event) => {
199
245
  if (popup && event.target !== popup && !popup.contains(event.target)) {
200
246
  popup.remove();
201
247
  popup = undefined;
248
+ if (toastElement) {
249
+ toastElement.remove();
250
+ toastElement = undefined;
251
+ }
252
+ if (toastTimeout !== undefined) {
253
+ clearTimeout(toastTimeout);
254
+ }
255
+ document.body.removeEventListener("click", closePopupHandler, true);
202
256
  }
203
- }, true);
204
- var input = document.createElement("input");
205
- input.type = "text";
206
- input.value = this.config.createShareableLink(this);
207
- input.onfocus = function () {
208
- input.select();
209
- };
210
- input.onmouseup = function () {
211
- return false;
212
257
  };
258
+ document.body.addEventListener("click", closePopupHandler, true);
213
259
  popup.innerHTML = "";
214
- var inputWrapper = document.createElement("div");
215
- inputWrapper.className = "inputWrapper";
216
- inputWrapper.appendChild(input);
217
- popup.appendChild(inputWrapper);
218
- const popupInputButtons = [];
260
+ const copyToClipboard = (text_1, buttonText_1, ...args_1) => __awaiter(this, [text_1, buttonText_1, ...args_1], void 0, function* (text, buttonText, hasAuth = false) {
261
+ try {
262
+ if (!navigator.clipboard || !navigator.clipboard.writeText) {
263
+ const textArea = document.createElement("textarea");
264
+ textArea.value = text;
265
+ textArea.style.position = "fixed";
266
+ textArea.style.left = "-999999px";
267
+ document.body.appendChild(textArea);
268
+ textArea.select();
269
+ try {
270
+ document.execCommand("copy");
271
+ document.body.removeChild(textArea);
272
+ showToast(`${buttonText} copied to clipboard!`);
273
+ }
274
+ catch (err) {
275
+ document.body.removeChild(textArea);
276
+ throw new Error("Copy command not supported");
277
+ }
278
+ }
279
+ else {
280
+ yield navigator.clipboard.writeText(text);
281
+ showToast(`${buttonText} copied to clipboard!`);
282
+ }
283
+ if (hasAuth) {
284
+ setTimeout(() => {
285
+ showToast("Warning: Authentication credentials included in copied content", TOAST_WARNING_DURATION, "warning");
286
+ }, TOAST_WARNING_DELAY);
287
+ }
288
+ }
289
+ catch (err) {
290
+ console.error("Failed to copy to clipboard:", err);
291
+ showToast("Failed to copy to clipboard. Please copy manually.", 2000);
292
+ }
293
+ });
294
+ const title = document.createElement("div");
295
+ title.className = "yasqe_sharePopup_title";
296
+ title.textContent = "Share Query";
297
+ popup.appendChild(title);
298
+ const buttonContainer = document.createElement("div");
299
+ buttonContainer.className = "yasqe_sharePopup_buttons";
300
+ popup.appendChild(buttonContainer);
301
+ const urlBtn = document.createElement("button");
302
+ urlBtn.innerText = "Copy URL";
303
+ urlBtn.className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn";
304
+ buttonContainer.appendChild(urlBtn);
305
+ urlBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
306
+ const url = this.config.createShareableLink(this);
307
+ yield copyToClipboard(url, "URL");
308
+ });
219
309
  const createShortLink = this.config.createShortLink;
220
310
  if (createShortLink) {
221
- popup.className = popup.className += " enableShort";
222
- const shortBtn = document.createElement("button");
223
- popupInputButtons.push(shortBtn);
224
- shortBtn.innerHTML = "Shorten";
225
- shortBtn.className = "yasqe_btn yasqe_btn-sm shorten";
226
- popup.appendChild(shortBtn);
227
- shortBtn.onclick = () => {
228
- popupInputButtons.forEach((button) => (button.disabled = true));
229
- createShortLink(this, input.value).then((value) => {
230
- input.value = value;
231
- input.focus();
232
- }, (err) => {
233
- const errSpan = document.createElement("span");
234
- errSpan.className = "shortlinkErr";
235
- let textContent = "An error has occurred";
311
+ const shortenBtn = document.createElement("button");
312
+ shortenBtn.innerText = "Shorten URL";
313
+ shortenBtn.className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn";
314
+ buttonContainer.appendChild(shortenBtn);
315
+ shortenBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
316
+ shortenBtn.disabled = true;
317
+ shortenBtn.innerText = "Shortening...";
318
+ try {
319
+ const longUrl = this.config.createShareableLink(this);
320
+ const shortUrl = yield createShortLink(this, longUrl);
321
+ yield copyToClipboard(shortUrl, "Shortened URL");
322
+ shortenBtn.innerText = "Shorten URL";
323
+ shortenBtn.disabled = false;
324
+ }
325
+ catch (err) {
326
+ shortenBtn.innerText = "Shorten URL";
327
+ shortenBtn.disabled = false;
328
+ let errorMsg = "Failed to shorten URL";
236
329
  if (typeof err === "string" && err.length !== 0) {
237
- textContent = err;
330
+ errorMsg = err;
238
331
  }
239
332
  else if (err.message && err.message.length !== 0) {
240
- textContent = err.message;
333
+ errorMsg = err.message;
241
334
  }
242
- errSpan.textContent = textContent;
243
- input.replaceWith(errSpan);
244
- });
245
- };
335
+ showToast(errorMsg, 3000);
336
+ }
337
+ });
246
338
  }
247
339
  const curlBtn = document.createElement("button");
248
- popupInputButtons.push(curlBtn);
249
- curlBtn.innerText = "cURL";
250
- curlBtn.className = "yasqe_btn yasqe_btn-sm curl";
251
- popup.appendChild(curlBtn);
252
- curlBtn.onclick = () => {
253
- popupInputButtons.forEach((button) => (button.disabled = true));
254
- input.value = this.getAsCurlString();
255
- input.focus();
256
- popup === null || popup === void 0 ? void 0 : popup.appendChild(curlBtn);
340
+ curlBtn.innerText = "Copy cURL";
341
+ curlBtn.className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn";
342
+ buttonContainer.appendChild(curlBtn);
343
+ curlBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
344
+ const curlString = this.getAsCurlString();
345
+ const hasAuth = this.hasAuthenticationCredentials();
346
+ yield copyToClipboard(curlString, "cURL command", hasAuth);
347
+ });
348
+ const psBtn = document.createElement("button");
349
+ psBtn.innerText = "Copy PowerShell";
350
+ psBtn.className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn";
351
+ buttonContainer.appendChild(psBtn);
352
+ psBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
353
+ const psString = this.getAsPowerShellString();
354
+ const hasAuth = this.hasAuthenticationCredentials();
355
+ yield copyToClipboard(psString, "PowerShell command", hasAuth);
356
+ });
357
+ const wgetBtn = document.createElement("button");
358
+ wgetBtn.innerText = "Copy wget";
359
+ wgetBtn.className = "yasqe_btn yasqe_btn-sm yasqe_shareBtn";
360
+ buttonContainer.appendChild(wgetBtn);
361
+ wgetBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
362
+ const wgetString = this.getAsWgetString();
363
+ const hasAuth = this.hasAuthenticationCredentials();
364
+ yield copyToClipboard(wgetString, "wget command", hasAuth);
365
+ });
366
+ const positionPopup = () => {
367
+ if (!popup)
368
+ return;
369
+ const svgPos = svgShare.getBoundingClientRect();
370
+ popup.style.top = svgShare.offsetTop + svgPos.height + "px";
371
+ popup.style.left = svgShare.offsetLeft + svgShare.clientWidth - popup.clientWidth + "px";
257
372
  };
258
- const svgPos = svgShare.getBoundingClientRect();
259
- popup.style.top = svgShare.offsetTop + svgPos.height + "px";
260
- popup.style.left = svgShare.offsetLeft + svgShare.clientWidth - popup.clientWidth + "px";
261
- input.focus();
373
+ if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {
374
+ window.requestAnimationFrame(positionPopup);
375
+ }
376
+ else {
377
+ setTimeout(positionPopup, 0);
378
+ }
262
379
  };
263
380
  }
264
381
  if (this.config.showQueryButton) {
@@ -1089,6 +1206,16 @@ export class Yasqe extends CodeMirror {
1089
1206
  getAsCurlString(config) {
1090
1207
  return Sparql.getAsCurlString(this, config);
1091
1208
  }
1209
+ getAsPowerShellString(config) {
1210
+ return Sparql.getAsPowerShellString(this, config);
1211
+ }
1212
+ getAsWgetString(config) {
1213
+ return Sparql.getAsWgetString(this, config);
1214
+ }
1215
+ hasAuthenticationCredentials(config) {
1216
+ const ajaxConfig = Sparql.getAjaxConfig(this, config);
1217
+ return ajaxConfig ? Sparql.hasAuthenticationCredentials(ajaxConfig) : false;
1218
+ }
1092
1219
  abortQuery() {
1093
1220
  if (this.req) {
1094
1221
  if (this.abortController) {