@hubspot/ui-extensions-dev-server 1.1.0 → 1.1.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.
Files changed (95) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.js +4 -0
  3. package/dist/lib/DevModeInterface.d.ts +9 -0
  4. package/dist/lib/DevModeInterface.js +36 -0
  5. package/dist/lib/DevModeParentInterface.d.ts +19 -0
  6. package/dist/lib/DevModeParentInterface.js +181 -0
  7. package/dist/lib/DevModeUnifiedInterface.d.ts +9 -0
  8. package/dist/lib/DevModeUnifiedInterface.js +118 -0
  9. package/dist/lib/DevServerState.d.ts +44 -0
  10. package/dist/lib/DevServerState.js +95 -0
  11. package/dist/lib/ExtensionsWebSocket.d.ts +25 -0
  12. package/dist/lib/ExtensionsWebSocket.js +110 -0
  13. package/dist/lib/__mocks__/config.d.ts +2 -0
  14. package/dist/lib/__mocks__/config.js +5 -0
  15. package/dist/lib/__mocks__/isExtensionFile.d.ts +5 -0
  16. package/dist/lib/__mocks__/isExtensionFile.js +11 -0
  17. package/dist/lib/__tests__/DevModeInterface.spec.d.ts +1 -0
  18. package/dist/lib/__tests__/DevModeInterface.spec.js +155 -0
  19. package/dist/lib/__tests__/DevModeParentInterface.spec.d.ts +1 -0
  20. package/dist/lib/__tests__/DevModeParentInterface.spec.js +179 -0
  21. package/dist/lib/__tests__/DevModeUnifiedInterface.spec.d.ts +1 -0
  22. package/dist/lib/__tests__/DevModeUnifiedInterface.spec.js +236 -0
  23. package/dist/lib/__tests__/ExtensionsWebSocket.spec.d.ts +1 -0
  24. package/dist/lib/__tests__/ExtensionsWebSocket.spec.js +304 -0
  25. package/dist/lib/__tests__/ast.spec.d.ts +1 -0
  26. package/dist/lib/__tests__/ast.spec.js +737 -0
  27. package/dist/lib/__tests__/build.spec.d.ts +1 -0
  28. package/dist/lib/__tests__/build.spec.js +159 -0
  29. package/dist/lib/__tests__/config.spec.d.ts +1 -0
  30. package/dist/lib/__tests__/config.spec.js +291 -0
  31. package/dist/lib/__tests__/dev.spec.d.ts +1 -0
  32. package/dist/lib/__tests__/dev.spec.js +80 -0
  33. package/dist/lib/__tests__/extensionsService.spec.d.ts +1 -0
  34. package/dist/lib/__tests__/extensionsService.spec.js +150 -0
  35. package/dist/lib/__tests__/factories.d.ts +48 -0
  36. package/dist/lib/__tests__/factories.js +32 -0
  37. package/dist/lib/__tests__/fixtures/extensionConfig.d.ts +182 -0
  38. package/dist/lib/__tests__/fixtures/extensionConfig.js +304 -0
  39. package/dist/lib/__tests__/fixtures/urls.d.ts +4 -0
  40. package/dist/lib/__tests__/fixtures/urls.js +4 -0
  41. package/dist/lib/__tests__/parsing-utils.spec.d.ts +1 -0
  42. package/dist/lib/__tests__/parsing-utils.spec.js +467 -0
  43. package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.d.ts +1 -0
  44. package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.js +112 -0
  45. package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.d.ts +1 -0
  46. package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.js +111 -0
  47. package/dist/lib/__tests__/plugins/devBuildPlugin.spec.d.ts +1 -0
  48. package/dist/lib/__tests__/plugins/devBuildPlugin.spec.js +345 -0
  49. package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.d.ts +1 -0
  50. package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.js +65 -0
  51. package/dist/lib/__tests__/plugins/manifestPlugin.spec.d.ts +1 -0
  52. package/dist/lib/__tests__/plugins/manifestPlugin.spec.js +455 -0
  53. package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.d.ts +1 -0
  54. package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.js +81 -0
  55. package/dist/lib/__tests__/server.spec.d.ts +1 -0
  56. package/dist/lib/__tests__/server.spec.js +152 -0
  57. package/dist/lib/__tests__/test-utils/ast.d.ts +1 -0
  58. package/dist/lib/__tests__/test-utils/ast.js +4 -0
  59. package/dist/lib/__tests__/utils.spec.d.ts +1 -0
  60. package/dist/lib/__tests__/utils.spec.js +176 -0
  61. package/dist/lib/ast.d.ts +16 -0
  62. package/dist/lib/ast.js +281 -0
  63. package/dist/lib/bin/cli.d.ts +2 -0
  64. package/dist/lib/bin/cli.js +143 -0
  65. package/dist/lib/build.d.ts +24 -0
  66. package/dist/lib/build.js +73 -0
  67. package/dist/lib/config.d.ts +7 -0
  68. package/dist/lib/config.js +124 -0
  69. package/dist/lib/constants.d.ts +32 -0
  70. package/dist/lib/constants.js +43 -0
  71. package/dist/lib/dev.d.ts +2 -0
  72. package/dist/lib/dev.js +58 -0
  73. package/dist/lib/extensionsService.d.ts +10 -0
  74. package/dist/lib/extensionsService.js +45 -0
  75. package/dist/lib/parsing-utils.d.ts +31 -0
  76. package/dist/lib/parsing-utils.js +289 -0
  77. package/dist/lib/plugins/codeBlockingPlugin.d.ts +8 -0
  78. package/dist/lib/plugins/codeBlockingPlugin.js +45 -0
  79. package/dist/lib/plugins/codeCheckingPlugin.d.ts +8 -0
  80. package/dist/lib/plugins/codeCheckingPlugin.js +89 -0
  81. package/dist/lib/plugins/devBuildPlugin.d.ts +8 -0
  82. package/dist/lib/plugins/devBuildPlugin.js +201 -0
  83. package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +14 -0
  84. package/dist/lib/plugins/friendlyLoggingPlugin.js +36 -0
  85. package/dist/lib/plugins/manifestPlugin.d.ts +12 -0
  86. package/dist/lib/plugins/manifestPlugin.js +158 -0
  87. package/dist/lib/plugins/relevantModulesPlugin.d.ts +13 -0
  88. package/dist/lib/plugins/relevantModulesPlugin.js +25 -0
  89. package/dist/lib/server.d.ts +13 -0
  90. package/dist/lib/server.js +99 -0
  91. package/dist/lib/types.d.ts +290 -0
  92. package/dist/lib/types.js +12 -0
  93. package/dist/lib/utils.d.ts +25 -0
  94. package/dist/lib/utils.js +113 -0
  95. package/package.json +1 -1
@@ -0,0 +1,113 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { MANIFEST_FILE } from "./constants.js";
4
+ export function getUrlSafeFileName(filePath) {
5
+ const { name } = path.parse(filePath);
6
+ return encodeURIComponent(`${name}.js`);
7
+ }
8
+ // Strips ANSI color codes out of strings because we don't want to pass them to the browser
9
+ export function stripAnsiColorCodes(stringWithColorCodes) {
10
+ if (!stringWithColorCodes) {
11
+ return null;
12
+ }
13
+ return stringWithColorCodes.replace(
14
+ // eslint-disable-next-line no-control-regex
15
+ /[\u001b][[]*([0-9]{1,4};?)*[m]/g, '');
16
+ }
17
+ export function loadManifest(outputDir, output) {
18
+ try {
19
+ return JSON.parse(fs
20
+ .readFileSync(path.join(outputDir, `${output}-${MANIFEST_FILE}`))
21
+ .toString());
22
+ }
23
+ catch (e) {
24
+ return {};
25
+ }
26
+ }
27
+ export function buildSourceId(appConfig, extensionConfig) {
28
+ if (appConfig.uid && extensionConfig.data.uid) {
29
+ return `${appConfig.uid}::${extensionConfig.data.uid}`;
30
+ }
31
+ return null;
32
+ }
33
+ export function isNodeModule(filepath) {
34
+ if (!filepath) {
35
+ return false;
36
+ }
37
+ const directory = path.parse(filepath).dir;
38
+ return directory.includes('node_modules');
39
+ }
40
+ /**
41
+ * Check if a given file is within the extension path
42
+ */
43
+ export function isExtensionFile(filepath, extensionPath) {
44
+ if (!filepath) {
45
+ return false;
46
+ }
47
+ try {
48
+ const absoluteFilePath = fs.realpathSync(filepath);
49
+ const absoluteExtensionDirPath = fs.realpathSync(extensionPath);
50
+ const relativePath = path.relative(absoluteExtensionDirPath, absoluteFilePath);
51
+ return !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
52
+ }
53
+ catch (e) {
54
+ console.log(`Error checking if ${filepath} is in extension path: ${e}`);
55
+ // If there's an error, we can't determine if the file is in the extension path, so return false.
56
+ return false;
57
+ }
58
+ }
59
+ export class UnhandledPlatformVersionError extends Error {
60
+ constructor(platformVersion) {
61
+ super(`Unsupported platform version "${platformVersion}"`);
62
+ }
63
+ }
64
+ export function throwUnhandledPlatformVersionError(platformVersion) {
65
+ throw new UnhandledPlatformVersionError(platformVersion);
66
+ }
67
+ export function extractAllowedUrls(appConfig) {
68
+ if (!appConfig || !('allowedUrls' in appConfig) || !appConfig.allowedUrls) {
69
+ return [];
70
+ }
71
+ return appConfig.allowedUrls;
72
+ }
73
+ function simpleHash(input) {
74
+ let hash = 0;
75
+ for (let i = 0; i < input.length; i++) {
76
+ const char = input.charCodeAt(i);
77
+ hash = (hash * 31 + char) % 2147483647;
78
+ }
79
+ return Math.abs(hash).toString(16);
80
+ }
81
+ /**
82
+ * This function generates a deterministic hash from any number of arguments
83
+ * Arrays and objects are stringified to ensure it works for all types.
84
+ * Uses the same simple hash algorithm as the browser version for consistency.
85
+ */
86
+ export function generateHash(...args) {
87
+ try {
88
+ // First make sure all the values are strings
89
+ const normalizedArgs = args.map((arg) => {
90
+ if (Array.isArray(arg)) {
91
+ return [...arg].sort().join('-');
92
+ }
93
+ if (arg && typeof arg === 'object') {
94
+ return JSON.stringify(arg, Object.keys(arg).sort());
95
+ }
96
+ return String(arg);
97
+ });
98
+ // Return the hash of the joined strings.
99
+ const input = [...normalizedArgs].join('::');
100
+ return simpleHash(input);
101
+ }
102
+ catch (e) {
103
+ console.error('Error generating hash: ', e);
104
+ // Just return an empty string if anything goes wrong.
105
+ return '';
106
+ }
107
+ }
108
+ /**
109
+ * Check if a given URL is an image (of a type we support)
110
+ */
111
+ export function isImage(url) {
112
+ return /\.(png|jpg|jpeg|gif|svg|webp|avif|raw|url|inline)$/.test(url);
113
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {