@hubspot/ui-extensions-dev-server 0.9.2 → 0.9.3

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/dist/index.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.DevModeUnifiedInterfaceNonSingleton = exports.DevModeUnifiedInterface = exports.DevModeInterfaceNonSingleton = exports.DevModeInterface = exports.buildSingleExtension = exports.remoteBuild = void 0;
27
37
  const build_1 = require("./lib/build");
@@ -63,9 +63,9 @@ class DevModeParentInterface {
63
63
  this.isConfigured = false;
64
64
  this.isRunning = false;
65
65
  }
66
- parentSetup({ onUploadRequired, promptUser, logger, urls, setActiveApp, choices = [], }) {
67
- var _a, _b, _c;
68
- return __awaiter(this, void 0, void 0, function* () {
66
+ parentSetup(_a) {
67
+ return __awaiter(this, arguments, void 0, function* ({ onUploadRequired, promptUser, logger, urls, setActiveApp, choices = [], }) {
68
+ var _b, _c, _d;
69
69
  if (this.isConfigured) {
70
70
  logger.debug('Dev server has already been configured, skipping');
71
71
  return;
@@ -100,13 +100,13 @@ class DevModeParentInterface {
100
100
  }
101
101
  this.isConfigured = true;
102
102
  if (typeof setActiveApp === 'function') {
103
- yield setActiveApp((_c = (_b = (_a = this.configs) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.appConfig) === null || _c === void 0 ? void 0 : _c.uid);
103
+ yield setActiveApp((_d = (_c = (_b = this.configs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.appConfig) === null || _d === void 0 ? void 0 : _d.uid);
104
104
  }
105
105
  });
106
106
  }
107
- start({ requestPorts, accountId, projectConfig, }) {
108
- var _a, _b, _c, _d;
109
- return __awaiter(this, void 0, void 0, function* () {
107
+ start(_a) {
108
+ return __awaiter(this, arguments, void 0, function* ({ requestPorts, accountId, projectConfig, }) {
109
+ var _b, _c, _d, _e;
110
110
  this.logger.debug('Start function was invoked', {
111
111
  accountId,
112
112
  projectConfig,
@@ -133,7 +133,7 @@ class DevModeParentInterface {
133
133
  this.logger.debug('Call to port manager failed, using default ports');
134
134
  }
135
135
  }
136
- const { proxy: localDevUrlMapping } = (0, config_1.loadLocalConfig)(((_b = (_a = this.configs) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.path) || '', this.logger) || {};
136
+ const { proxy: localDevUrlMapping } = (0, config_1.loadLocalConfig)(((_c = (_b = this.configs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.path) || '', this.logger) || {};
137
137
  try {
138
138
  this.devServerState = new DevServerState_1.DevServerState({
139
139
  localDevUrlMapping,
@@ -144,7 +144,7 @@ class DevModeParentInterface {
144
144
  webSocketPort,
145
145
  logger: this.logger,
146
146
  urls: this.urls,
147
- appConfig: (_d = (_c = this.configs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.appConfig,
147
+ appConfig: (_e = (_d = this.configs) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.appConfig,
148
148
  });
149
149
  }
150
150
  catch (e) {
package/dist/lib/ast.d.ts CHANGED
@@ -1,5 +1,15 @@
1
1
  import { SourceCodeMetadata, SourceCodeChecks, Logger } from './types';
2
2
  import { Program, Node } from 'estree';
3
+ type NodeValue = string | number | boolean | null | undefined | RegExp | bigint | NodeValue[] | NodeObject;
4
+ type NodeObject = {
5
+ [key: string]: NodeValue;
6
+ };
7
+ /**
8
+ * This is a simple utility function to rebuild the value from a node.
9
+ * It'll work for simple stuff, but it's likely to fail in complicated cases.
10
+ * Use with caution!
11
+ */
12
+ export declare function getValueFromNode(node: Node): NodeValue;
3
13
  /**
4
14
  * We only support image imports that are within the extension directory.
5
15
  * This function will check if an image is out of bounds and collect any that are out of bounds, so we can warn the user before they run into build issues.
@@ -13,3 +23,4 @@ export declare function traverseAbstractSyntaxTree(ast: Program, checks: SourceC
13
23
  dependencies: never[];
14
24
  };
15
25
  };
26
+ export {};
package/dist/lib/ast.js CHANGED
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.traverseAbstractSyntaxTree = exports.checkForOutOfBoundsImageImports = void 0;
7
+ exports.getValueFromNode = getValueFromNode;
8
+ exports.checkForOutOfBoundsImageImports = checkForOutOfBoundsImageImports;
9
+ exports.traverseAbstractSyntaxTree = traverseAbstractSyntaxTree;
8
10
  const path_1 = __importDefault(require("path"));
9
11
  // @ts-expect-error no type defs
10
12
  const estraverse_1 = require("estraverse");
@@ -53,6 +55,53 @@ function _checkForFunctionMetadata(node, parent, output, functionName) {
53
55
  output.functions[functionName].defined = true;
54
56
  }
55
57
  }
58
+ /**
59
+ * This is a simple utility function to rebuild the value from a node.
60
+ * It'll work for simple stuff, but it's likely to fail in complicated cases.
61
+ * Use with caution!
62
+ */
63
+ function getValueFromNode(node) {
64
+ switch (node.type) {
65
+ case 'Literal':
66
+ return node.value;
67
+ case 'Identifier': {
68
+ const name = node.name;
69
+ switch (name) {
70
+ case 'undefined':
71
+ return undefined;
72
+ case 'NaN':
73
+ return NaN;
74
+ case 'Infinity':
75
+ return Infinity;
76
+ default:
77
+ return name;
78
+ }
79
+ }
80
+ case 'ArrayExpression':
81
+ return node.elements.map((element) => element ? getValueFromNode(element) : null);
82
+ case 'ObjectExpression': {
83
+ const obj = {};
84
+ node.properties.forEach((prop) => {
85
+ if (prop.type === 'Property') {
86
+ const property = prop;
87
+ let key = undefined;
88
+ if (property.key.type === 'Identifier') {
89
+ key = property.key.name;
90
+ }
91
+ else if (property.key.type === 'Literal') {
92
+ key = String(property.key.value);
93
+ }
94
+ if (key) {
95
+ obj[key] = getValueFromNode(property.value);
96
+ }
97
+ }
98
+ });
99
+ return obj;
100
+ }
101
+ default:
102
+ return `Unsupported node type: ${node.type}`;
103
+ }
104
+ }
56
105
  /**
57
106
  * We only support image imports that are within the extension directory.
58
107
  * This function will check if an image is out of bounds and collect any that are out of bounds, so we can warn the user before they run into build issues.
@@ -75,7 +124,6 @@ function checkForOutOfBoundsImageImports(node, output, extensionPath) {
75
124
  }
76
125
  }
77
126
  }
78
- exports.checkForOutOfBoundsImageImports = checkForOutOfBoundsImageImports;
79
127
  /**
80
128
  * This function collects all internal data dependencies for the extension
81
129
  * Specifically, it collects dependencies which are using our custom hooks, eg `useCrmProperties`
@@ -134,6 +182,7 @@ function _collectDataDependencies(node, output, logger) {
134
182
  const propertyType = 'CrmRecordProperties';
135
183
  // Get the first argument, the properties array
136
184
  const propertiesNode = node.arguments[0];
185
+ const optionsNode = node.arguments[1];
137
186
  const requestedProperties = [];
138
187
  // If the first argument is an array with at least one element, collect the properties.
139
188
  if (propertiesNode &&
@@ -154,6 +203,17 @@ function _collectDataDependencies(node, output, logger) {
154
203
  }
155
204
  });
156
205
  if (requestedProperties.length > 0) {
206
+ let options = {};
207
+ if (optionsNode) {
208
+ const optionsValue = getValueFromNode(optionsNode);
209
+ if (optionsValue !== null &&
210
+ optionsValue !== undefined &&
211
+ typeof optionsValue === 'object' &&
212
+ !Array.isArray(optionsValue) &&
213
+ !(optionsValue instanceof RegExp)) {
214
+ options = optionsValue;
215
+ }
216
+ }
157
217
  output.dataDependencies.dependencies.push({
158
218
  /**
159
219
  * This refID is a hash of the property type and the requested properties.
@@ -163,6 +223,7 @@ function _collectDataDependencies(node, output, logger) {
163
223
  properties: {
164
224
  type: propertyType,
165
225
  recordProperties: requestedProperties,
226
+ options,
166
227
  },
167
228
  });
168
229
  }
@@ -207,4 +268,3 @@ function traverseAbstractSyntaxTree(ast, checks, extensionPath, logger) {
207
268
  }
208
269
  return state;
209
270
  }
210
- exports.traverseAbstractSyntaxTree = traverseAbstractSyntaxTree;
package/dist/lib/build.js CHANGED
@@ -12,7 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.remoteBuild = exports.buildSingleExtension = exports.extensionErrorBaseMessage = void 0;
15
+ exports.extensionErrorBaseMessage = void 0;
16
+ exports.buildSingleExtension = buildSingleExtension;
17
+ exports.remoteBuild = remoteBuild;
16
18
  const vite_1 = require("vite");
17
19
  const constants_1 = require("./constants");
18
20
  const manifestPlugin_1 = __importDefault(require("./plugins/manifestPlugin"));
@@ -22,9 +24,9 @@ const codeBlockingPlugin_1 = __importDefault(require("./plugins/codeBlockingPlug
22
24
  const friendlyLoggingPlugin_1 = __importDefault(require("./plugins/friendlyLoggingPlugin"));
23
25
  const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];
24
26
  exports.extensionErrorBaseMessage = `Supported file extensions are [${allowedExtensions.join(', ')}], received:`;
25
- function buildSingleExtension({ file, outputDir = constants_1.OUTPUT_DIR, emptyOutDir = true, minify = false, root = process.cwd(), // This is the vite default, so using that as our default
26
- logLevel = 'info', }) {
27
- return __awaiter(this, void 0, void 0, function* () {
27
+ function buildSingleExtension(_a) {
28
+ return __awaiter(this, arguments, void 0, function* ({ file, outputDir = constants_1.OUTPUT_DIR, emptyOutDir = true, minify = false, root = process.cwd(), // This is the vite default, so using that as our default
29
+ logLevel = 'info', }) {
28
30
  const output = (0, utils_1.getUrlSafeFileName)(file);
29
31
  yield (0, vite_1.build)({
30
32
  logLevel,
@@ -51,9 +53,8 @@ logLevel = 'info', }) {
51
53
  });
52
54
  });
53
55
  }
54
- exports.buildSingleExtension = buildSingleExtension;
55
- function remoteBuild(root, entryPoint, outputDir = constants_1.OUTPUT_DIR, logLevel) {
56
- return __awaiter(this, void 0, void 0, function* () {
56
+ function remoteBuild(root_1, entryPoint_1) {
57
+ return __awaiter(this, arguments, void 0, function* (root, entryPoint, outputDir = constants_1.OUTPUT_DIR, logLevel) {
57
58
  const fileInfo = path_1.default.parse(entryPoint);
58
59
  if (!allowedExtensions.includes(fileInfo.ext)) {
59
60
  throw new Error(`${exports.extensionErrorBaseMessage} ${fileInfo.ext}`);
@@ -67,4 +68,3 @@ function remoteBuild(root, entryPoint, outputDir = constants_1.OUTPUT_DIR, logLe
67
68
  });
68
69
  });
69
70
  }
70
- exports.remoteBuild = remoteBuild;
@@ -5,7 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.loadLocalConfig = exports.validateProxyConfigValue = exports.validateProxyConfigKey = exports.loadExtensionConfig = exports.validateCardConfig = exports.loadConfigByPath = void 0;
8
+ exports.loadConfigByPath = loadConfigByPath;
9
+ exports.validateCardConfig = validateCardConfig;
10
+ exports.loadExtensionConfig = loadExtensionConfig;
11
+ exports.validateProxyConfigKey = validateProxyConfigKey;
12
+ exports.validateProxyConfigValue = validateProxyConfigValue;
13
+ exports.loadLocalConfig = loadLocalConfig;
9
14
  const fs_1 = __importDefault(require("fs"));
10
15
  const path_1 = __importDefault(require("path"));
11
16
  const utils_1 = require("./utils");
@@ -13,7 +18,6 @@ function loadConfigByPath(configPath) {
13
18
  const source = fs_1.default.readFileSync(configPath).toString();
14
19
  return JSON.parse(source);
15
20
  }
16
- exports.loadConfigByPath = loadConfigByPath;
17
21
  function validateCardConfig(config) {
18
22
  if (!config || typeof config !== 'object') {
19
23
  return new Error('Card config must be an object');
@@ -50,7 +54,6 @@ function validateCardConfig(config) {
50
54
  }
51
55
  return true;
52
56
  }
53
- exports.validateCardConfig = validateCardConfig;
54
57
  function loadExtensionConfig(appConfig, appPath) {
55
58
  var _a, _b;
56
59
  const crmCardsSubConfigFiles = (_b = (_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.extensions) === null || _a === void 0 ? void 0 : _a.crm) === null || _b === void 0 ? void 0 : _b.cards;
@@ -81,7 +84,6 @@ function loadExtensionConfig(appConfig, appPath) {
81
84
  });
82
85
  return outputConfig;
83
86
  }
84
- exports.loadExtensionConfig = loadExtensionConfig;
85
87
  function validateProxyConfigKey(urlKey, logger, localConfigPath) {
86
88
  try {
87
89
  const url = new URL(urlKey);
@@ -93,7 +95,6 @@ function validateProxyConfigKey(urlKey, logger, localConfigPath) {
93
95
  logger.warn(`The key "${urlKey}" in "${localConfigPath}" is an invalid url`);
94
96
  }
95
97
  }
96
- exports.validateProxyConfigKey = validateProxyConfigKey;
97
98
  function validateProxyConfigValue(value, key, logger, localConfigPath) {
98
99
  try {
99
100
  // eslint-disable-next-line no-new
@@ -103,7 +104,6 @@ function validateProxyConfigValue(value, key, logger, localConfigPath) {
103
104
  logger.warn(`The value "${value}" for key "${key}" in "${localConfigPath}" is an invalid url`);
104
105
  }
105
106
  }
106
- exports.validateProxyConfigValue = validateProxyConfigValue;
107
107
  function loadLocalConfig(appPath, logger) {
108
108
  const localConfigFilename = 'local.json';
109
109
  const localConfigPath = path_1.default.join(appPath, localConfigFilename);
@@ -125,4 +125,3 @@ function loadLocalConfig(appPath, logger) {
125
125
  return undefined;
126
126
  }
127
127
  }
128
- exports.loadLocalConfig = loadLocalConfig;
package/dist/lib/dev.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.startDevMode = void 0;
15
+ exports.startDevMode = startDevMode;
16
16
  const vite_1 = require("vite");
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const server_1 = __importDefault(require("./server"));
@@ -73,4 +73,3 @@ function startDevMode(devServerState) {
73
73
  return shutdownServer;
74
74
  });
75
75
  }
76
- exports.startDevMode = startDevMode;
@@ -6,7 +6,7 @@ const ast_1 = require("../ast");
6
6
  const codeBlockingPlugin = ({ logger, extensionPath }) => {
7
7
  return {
8
8
  name: 'ui-extensions-code-blocking-plugin',
9
- enforce: 'post',
9
+ enforce: 'post', // run after default rollup plugins
10
10
  transform(code, filename) {
11
11
  if ((0, utils_1.isNodeModule)(filename)) {
12
12
  return { code, map: null }; // We don't want to parse node modules
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
17
17
  }) : function(o, v) {
18
18
  o["default"] = v;
19
19
  });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
27
37
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
38
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
39
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -68,7 +78,7 @@ const devBuildPlugin = (options) => {
68
78
  } }));
69
79
  }
70
80
  };
71
- const devBuild = (server, extensionMetadata, emptyOutDir = false) => __awaiter(void 0, void 0, void 0, function* () {
81
+ const devBuild = (server_1, extensionMetadata_1, ...args_1) => __awaiter(void 0, [server_1, extensionMetadata_1, ...args_1], void 0, function* (server, extensionMetadata, emptyOutDir = false) {
72
82
  try {
73
83
  const { config: extensionConfig } = extensionMetadata;
74
84
  const { extensionPath } = extensionConfig;
@@ -151,7 +161,7 @@ const devBuildPlugin = (options) => {
151
161
  yield devBuild(localServer, devServerState.extensionsMetadata[i], i === 0);
152
162
  }
153
163
  }),
154
- handleHotUpdate: ({ file, server }) => __awaiter(void 0, void 0, void 0, function* () {
164
+ handleHotUpdate: (_a) => __awaiter(void 0, [_a], void 0, function* ({ file, server }) {
155
165
  // If the file is not in the relevantModules list, it's update is inconsequential
156
166
  const extensionsToRebuild = devServerState.extensionsMetadata.filter((metadata) => {
157
167
  const { config } = metadata;
@@ -17,7 +17,7 @@ const manifestPlugin = (options) => {
17
17
  let allDataDependencies;
18
18
  return {
19
19
  name: 'ui-extensions-manifest-generation-plugin',
20
- enforce: 'post',
20
+ enforce: 'post', // run after default rollup plugins
21
21
  buildStart() {
22
22
  // Reset the source metadata for the new build
23
23
  allDataDependencies = [];
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRelevantModules = void 0;
3
+ exports.getRelevantModules = getRelevantModules;
4
4
  const utils_1 = require("../utils");
5
5
  const relevantModules = {};
6
6
  function getRelevantModules(output) {
7
7
  return relevantModules[output] || [];
8
8
  }
9
- exports.getRelevantModules = getRelevantModules;
10
9
  const relevantModulesPlugin = ({ output, logger }) => {
11
10
  return {
12
11
  name: 'ui-extensions-relevant-modules-plugin',
@@ -31,9 +31,9 @@ function listen(app, port) {
31
31
  });
32
32
  });
33
33
  }
34
- function startDevServer({ devServerState, viteDevServer, }) {
35
- var _a;
36
- return __awaiter(this, void 0, void 0, function* () {
34
+ function startDevServer(_a) {
35
+ return __awaiter(this, arguments, void 0, function* ({ devServerState, viteDevServer, }) {
36
+ var _b;
37
37
  const app = (0, express_1.default)();
38
38
  // Setup middleware
39
39
  app.use((0, cors_1.default)());
@@ -75,7 +75,7 @@ function startDevServer({ devServerState, viteDevServer, }) {
75
75
  }
76
76
  throw new Error(e);
77
77
  }
78
- (_a = devServerState.extensionsMetadata) === null || _a === void 0 ? void 0 : _a.forEach((metadata) => {
78
+ (_b = devServerState.extensionsMetadata) === null || _b === void 0 ? void 0 : _b.forEach((metadata) => {
79
79
  const { baseMessage } = metadata;
80
80
  devServerState.logger.debug(`Listening at ${baseMessage.callback}`);
81
81
  });
@@ -203,6 +203,9 @@ export type DataDependency = {
203
203
  properties: {
204
204
  type: string;
205
205
  recordProperties: string[];
206
+ options: {
207
+ [key: string]: any;
208
+ };
206
209
  };
207
210
  };
208
211
  export interface SourceCodeMetadata {
@@ -16,6 +16,7 @@ export declare function extractAllowedUrls(appConfig?: AppConfig): string[];
16
16
  /**
17
17
  * This function generates a deterministic hash from any number of arguments
18
18
  * Arrays and objects are stringified to ensure it works for all types.
19
+ * Uses the same simple hash algorithm as the browser version for consistency.
19
20
  */
20
21
  export declare function generateHash(...args: unknown[]): string;
21
22
  /**
package/dist/lib/utils.js CHANGED
@@ -3,16 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isImage = exports.generateHash = exports.extractAllowedUrls = exports.throwUnhandledPlatformVersionError = exports.UnhandledPlatformVersionError = exports.isExtensionFile = exports.isNodeModule = exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
6
+ exports.UnhandledPlatformVersionError = void 0;
7
+ exports.getUrlSafeFileName = getUrlSafeFileName;
8
+ exports.stripAnsiColorCodes = stripAnsiColorCodes;
9
+ exports.loadManifest = loadManifest;
10
+ exports.buildSourceId = buildSourceId;
11
+ exports.isNodeModule = isNodeModule;
12
+ exports.isExtensionFile = isExtensionFile;
13
+ exports.throwUnhandledPlatformVersionError = throwUnhandledPlatformVersionError;
14
+ exports.extractAllowedUrls = extractAllowedUrls;
15
+ exports.generateHash = generateHash;
16
+ exports.isImage = isImage;
7
17
  const path_1 = __importDefault(require("path"));
8
18
  const fs_1 = __importDefault(require("fs"));
9
- const crypto_1 = require("crypto");
10
19
  const constants_1 = require("./constants");
11
20
  function getUrlSafeFileName(filePath) {
12
21
  const { name } = path_1.default.parse(filePath);
13
22
  return encodeURIComponent(`${name}.js`);
14
23
  }
15
- exports.getUrlSafeFileName = getUrlSafeFileName;
16
24
  // Strips ANSI color codes out of strings because we don't want to pass them to the browser
17
25
  function stripAnsiColorCodes(stringWithColorCodes) {
18
26
  if (!stringWithColorCodes) {
@@ -22,7 +30,6 @@ function stripAnsiColorCodes(stringWithColorCodes) {
22
30
  // eslint-disable-next-line no-control-regex
23
31
  /[\u001b][[]*([0-9]{1,4};?)*[m]/g, '');
24
32
  }
25
- exports.stripAnsiColorCodes = stripAnsiColorCodes;
26
33
  function loadManifest(outputDir, output) {
27
34
  try {
28
35
  return JSON.parse(fs_1.default
@@ -33,14 +40,12 @@ function loadManifest(outputDir, output) {
33
40
  return {};
34
41
  }
35
42
  }
36
- exports.loadManifest = loadManifest;
37
43
  function buildSourceId(appConfig, extensionConfig) {
38
44
  if (appConfig.uid && extensionConfig.data.uid) {
39
45
  return `${appConfig.uid}::${extensionConfig.data.uid}`;
40
46
  }
41
47
  return null;
42
48
  }
43
- exports.buildSourceId = buildSourceId;
44
49
  function isNodeModule(filepath) {
45
50
  if (!filepath) {
46
51
  return false;
@@ -48,7 +53,6 @@ function isNodeModule(filepath) {
48
53
  const directory = path_1.default.parse(filepath).dir;
49
54
  return directory.includes('node_modules');
50
55
  }
51
- exports.isNodeModule = isNodeModule;
52
56
  /**
53
57
  * Check if a given file is within the extension path
54
58
  */
@@ -68,7 +72,6 @@ function isExtensionFile(filepath, extensionPath) {
68
72
  return false;
69
73
  }
70
74
  }
71
- exports.isExtensionFile = isExtensionFile;
72
75
  class UnhandledPlatformVersionError extends Error {
73
76
  constructor(platformVersion) {
74
77
  super(`Unsupported platform version "${platformVersion}"`);
@@ -78,17 +81,24 @@ exports.UnhandledPlatformVersionError = UnhandledPlatformVersionError;
78
81
  function throwUnhandledPlatformVersionError(platformVersion) {
79
82
  throw new UnhandledPlatformVersionError(platformVersion);
80
83
  }
81
- exports.throwUnhandledPlatformVersionError = throwUnhandledPlatformVersionError;
82
84
  function extractAllowedUrls(appConfig) {
83
85
  if (!appConfig || !('allowedUrls' in appConfig) || !appConfig.allowedUrls) {
84
86
  return [];
85
87
  }
86
88
  return appConfig.allowedUrls;
87
89
  }
88
- exports.extractAllowedUrls = extractAllowedUrls;
90
+ function simpleHash(input) {
91
+ let hash = 0;
92
+ for (let i = 0; i < input.length; i++) {
93
+ const char = input.charCodeAt(i);
94
+ hash = (hash * 31 + char) % 2147483647;
95
+ }
96
+ return Math.abs(hash).toString(16);
97
+ }
89
98
  /**
90
99
  * This function generates a deterministic hash from any number of arguments
91
100
  * Arrays and objects are stringified to ensure it works for all types.
101
+ * Uses the same simple hash algorithm as the browser version for consistency.
92
102
  */
93
103
  function generateHash(...args) {
94
104
  try {
@@ -102,9 +112,9 @@ function generateHash(...args) {
102
112
  }
103
113
  return String(arg);
104
114
  });
115
+ // Return the hash of the joined strings.
105
116
  const input = [...normalizedArgs].join('::');
106
- // Return the hash of the joined string.
107
- return (0, crypto_1.createHash)('md5').update(input).digest('hex');
117
+ return simpleHash(input);
108
118
  }
109
119
  catch (e) {
110
120
  console.error('Error generating hash: ', e);
@@ -112,11 +122,9 @@ function generateHash(...args) {
112
122
  return '';
113
123
  }
114
124
  }
115
- exports.generateHash = generateHash;
116
125
  /**
117
126
  * Check if a given URL is an image (of a type we support)
118
127
  */
119
128
  function isImage(url) {
120
129
  return /\.(png|jpg|jpeg|gif|svg|webp|avif|raw|url|inline)$/.test(url);
121
130
  }
122
- exports.isImage = isImage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "uie": "./dist/lib/bin/cli.js"
@@ -70,5 +70,5 @@
70
70
  "optional": true
71
71
  }
72
72
  },
73
- "gitHead": "931c7cf7cc3f87a54909e67a0a7df74e4eee2c3b"
73
+ "gitHead": "a5c7f8d19d0dc16b44e9235d3e12dacc2cc14fdf"
74
74
  }