@stackql/provider-utils 0.4.9 → 0.5.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackql/provider-utils",
3
- "version": "0.4.9",
3
+ "version": "0.5.1",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -32,17 +32,16 @@ export function sanitizeHtml(text) {
32
32
  if (!text) return '';
33
33
 
34
34
  // Special handling for code tags - temporarily replace them with placeholders
35
- // that won't get escaped in the general sanitization
36
35
  let result = text
37
36
  // Replace <code> tags with a safe placeholder
38
37
  .replace(/<code>/g, '___CODE_OPEN___')
39
38
  .replace(/<\/code>/g, '___CODE_CLOSE___');
40
-
41
- // Remove <nobr> tags completely
39
+
40
+ // Remove <nobr> tags completely
42
41
  result = result
43
42
  .replace(/<nobr>/g, '')
44
43
  .replace(/<\/nobr>/g, '');
45
-
44
+
46
45
  // Then apply the general sanitization
47
46
  result = result
48
47
  .replace(/{/g, '&#123;')
@@ -51,17 +50,18 @@ export function sanitizeHtml(text) {
51
50
  .replace(/</g, '&lt;')
52
51
  // edge case
53
52
  .replace(/&#125;_&#123;/g, '&#125;&#95;&#123;')
53
+ // Handle all types of line breaks - very important!
54
+ .replace(/\r\n/g, '<br />')
55
+ .replace(/\r/g, '<br />')
54
56
  .replace(/\n/g, '<br />');
55
57
 
56
58
  // Fix 1: Replace &lt;br&gt;, &lt;br/&gt;, &lt;p&gt;, &lt;/p&gt; back to their literal HTML tags
57
- // Make sure <br> is always self-closing for MDX compatibility
58
59
  result = result
59
60
  .replace(/&lt;br\s*\/?&gt;/gi, '<br />')
60
61
  .replace(/&lt;p&gt;/gi, '<p>')
61
62
  .replace(/&lt;\/p&gt;/gi, '</p>');
62
63
 
63
- // Fix 2: Find any &lt; or &gt; inside backticks and convert them back to < and >
64
- // We need to handle the backtick content by finding pairs of backticks
64
+ // Fix 2: Handle backticked content more carefully
65
65
  result = result.replace(/`([^`]*)`/g, (match, content) => {
66
66
  // Convert &lt; and &gt; back to < and > only within backticked content
67
67
  const fixedContent = content
@@ -70,11 +70,16 @@ export function sanitizeHtml(text) {
70
70
  return '`' + fixedContent + '`';
71
71
  });
72
72
 
73
+ // IMPORTANT: Explicitly sanitize any <location> tags that might be in the text
74
+ // This ensures they get properly escaped even if added later
75
+ result = result.replace(/<location>/g, '&lt;location&gt;')
76
+ .replace(/<\/location>/g, '&lt;/location&gt;');
77
+
73
78
  // Finally, restore the code tags
74
79
  result = result
75
80
  .replace(/___CODE_OPEN___/g, '<code>')
76
81
  .replace(/___CODE_CLOSE___/g, '</code>');
77
-
82
+
78
83
  return result;
79
84
  }
80
85
 
@@ -63,6 +63,11 @@ function detectObjectKey(spec, operation) {
63
63
  return '';
64
64
  }
65
65
 
66
+ // Check for explicit x-stackql-objectKey first
67
+ if (operation['x-stackql-objectKey']) {
68
+ return operation['x-stackql-objectKey'];
69
+ }
70
+
66
71
  let responseObject = null;
67
72
  let responseCode = null;
68
73
 
@@ -341,11 +346,26 @@ export async function analyze(options) {
341
346
  // Find existing mapping if available
342
347
  let { resourceName, methodName, sqlVerb, objectKey } = findExistingMapping(spec, pathRef);
343
348
 
349
+ // Check for explicit x-stackql-resource in operation
350
+ if (operation['x-stackql-resource']) {
351
+ resourceName = operation['x-stackql-resource'];
352
+ }
353
+
354
+ // Check for explicit x-stackql-method in operation
355
+ if (operation['x-stackql-method']) {
356
+ methodName = operation['x-stackql-method'];
357
+ }
358
+
344
359
  // CHANGE 1: Default methodName to formattedOpId if not found
345
360
  if (!methodName) {
346
361
  methodName = formattedOpId;
347
362
  }
348
363
 
364
+ // Check for explicit x-stackql-sqlVerb in operation
365
+ if (operation['x-stackql-sqlVerb']) {
366
+ sqlVerb = operation['x-stackql-sqlVerb'];
367
+ }
368
+
349
369
  // CHANGE 2: Default sqlVerb based on HTTP verb if not found
350
370
  if (!sqlVerb) {
351
371
  sqlVerb = mapToSqlVerb(verb);