@hubspot/ui-extensions-dev-server 0.9.8 → 0.10.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/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");
@@ -67,9 +67,9 @@ class DevModeParentInterface {
67
67
  this.isConfigured = false;
68
68
  this.isRunning = false;
69
69
  }
70
- parentSetup({ onUploadRequired, logger, urls, setActiveApp, choices = [], }) {
71
- var _a, _b, _c;
72
- return __awaiter(this, void 0, void 0, function* () {
70
+ parentSetup(_a) {
71
+ return __awaiter(this, arguments, void 0, function* ({ onUploadRequired, logger, urls, setActiveApp, choices = [], }) {
72
+ var _b, _c, _d;
73
73
  if (this.isConfigured) {
74
74
  logger.debug('Dev server has already been configured, skipping');
75
75
  return;
@@ -105,13 +105,13 @@ class DevModeParentInterface {
105
105
  }
106
106
  this.isConfigured = true;
107
107
  if (typeof setActiveApp === 'function') {
108
- 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);
108
+ 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);
109
109
  }
110
110
  });
111
111
  }
112
- start({ requestPorts, accountId, projectConfig, }) {
113
- var _a, _b, _c, _d;
114
- return __awaiter(this, void 0, void 0, function* () {
112
+ start(_a) {
113
+ return __awaiter(this, arguments, void 0, function* ({ requestPorts, accountId, projectConfig, }) {
114
+ var _b, _c, _d, _e;
115
115
  this.logger.debug('Start function was invoked', {
116
116
  accountId,
117
117
  projectConfig,
@@ -138,7 +138,7 @@ class DevModeParentInterface {
138
138
  this.logger.debug('Call to port manager failed, using default ports');
139
139
  }
140
140
  }
141
- 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) || {};
141
+ 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) || {};
142
142
  try {
143
143
  this.devServerState = new DevServerState_1.DevServerState({
144
144
  localDevUrlMapping,
@@ -149,7 +149,7 @@ class DevModeParentInterface {
149
149
  webSocketPort,
150
150
  logger: this.logger,
151
151
  urls: this.urls,
152
- appConfig: (_d = (_c = this.configs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.appConfig,
152
+ appConfig: (_e = (_d = this.configs) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.appConfig,
153
153
  });
154
154
  }
155
155
  catch (e) {
@@ -1,7 +1,7 @@
1
- import { AppExtensionMapping, UnifiedProjectComponentMap, UnifiedDevModeSetupArguments } from './types';
1
+ import { AppExtensionMapping, UnifiedProjectComponentMap, UnifiedDevModeSetupArguments, ProfileVariables } from './types';
2
2
  import { DevModeParentInterface } from './DevModeParentInterface';
3
3
  declare class DevModeUnifiedInterface extends DevModeParentInterface {
4
- _generateAppExtensionMappings(components: UnifiedProjectComponentMap): AppExtensionMapping[];
4
+ _generateAppExtensionMappings(components: UnifiedProjectComponentMap, profileData?: ProfileVariables): AppExtensionMapping[];
5
5
  setup(args: UnifiedDevModeSetupArguments): Promise<void>;
6
6
  }
7
7
  export { DevModeUnifiedInterface as DevModeUnifiedInterfaceNonSingleton };
@@ -29,7 +29,7 @@ function getComponentName(componentType) {
29
29
  }
30
30
  }
31
31
  class DevModeUnifiedInterface extends DevModeParentInterface_1.DevModeParentInterface {
32
- _generateAppExtensionMappings(components) {
32
+ _generateAppExtensionMappings(components, profileData) {
33
33
  var _a, _b, _c, _d;
34
34
  const mappings = [];
35
35
  // Loop over all of the components that are passed in
@@ -63,6 +63,7 @@ class DevModeUnifiedInterface extends DevModeParentInterface_1.DevModeParentInte
63
63
  allowedUrls: ((_d = appData.config) === null || _d === void 0 ? void 0 : _d.permittedUrls)
64
64
  ? Object.values(appData.config.permittedUrls).flat()
65
65
  : [],
66
+ variables: profileData || {},
66
67
  };
67
68
  // Then get all the supported extensions
68
69
  const extensionUids = allComponentUids.filter((componentUid) => {
@@ -128,7 +129,8 @@ class DevModeUnifiedInterface extends DevModeParentInterface_1.DevModeParentInte
128
129
  }
129
130
  setup(args) {
130
131
  return __awaiter(this, void 0, void 0, function* () {
131
- args.choices = this._generateAppExtensionMappings(args.components);
132
+ var _a;
133
+ args.choices = this._generateAppExtensionMappings(args.components, (_a = args.profileData) !== null && _a !== void 0 ? _a : {});
132
134
  yield this.parentSetup(args);
133
135
  });
134
136
  }
package/dist/lib/ast.js CHANGED
@@ -4,7 +4,8 @@ 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.checkForOutOfBoundsImageImports = checkForOutOfBoundsImageImports;
8
+ exports.traverseAbstractSyntaxTree = traverseAbstractSyntaxTree;
8
9
  const path_1 = __importDefault(require("path"));
9
10
  // @ts-expect-error no type defs
10
11
  const estraverse_1 = require("estraverse");
@@ -82,7 +83,6 @@ function checkForOutOfBoundsImageImports(node, output, extensionPath) {
82
83
  }
83
84
  }
84
85
  }
85
- exports.checkForOutOfBoundsImageImports = checkForOutOfBoundsImageImports;
86
86
  function _processCrmPropertiesHook(node, output) {
87
87
  if (node.type !== 'CallExpression')
88
88
  return;
@@ -286,4 +286,3 @@ function traverseAbstractSyntaxTree(ast, checks, extensionPath, logger) {
286
286
  }
287
287
  return state;
288
288
  }
289
- exports.traverseAbstractSyntaxTree = traverseAbstractSyntaxTree;
@@ -46,6 +46,7 @@ const buildSteps = {
46
46
  },
47
47
  };
48
48
  program
49
+ .option('-v, --profile-variables <path>', 'path to a json file with profile variables')
49
50
  .command('build <module>', { isDefault: true })
50
51
  .description('Build extension source code.')
51
52
  .action((module) => __awaiter(void 0, void 0, void 0, function* () {
@@ -74,8 +75,15 @@ function runCommand(command, options) {
74
75
  });
75
76
  }
76
77
  // Mirrors: https://git.hubteam.com/HubSpot/Artifactor/blob/f5cbea91d7a7dfb6278e878ae583e69022384fb5/ArtifactorFunctions/functions/node_18x/uie-remote-build/index.js#L59-L63
77
- function build({ extensionRoot, extensionDist, entrypoint }) {
78
- return (0, build_1.remoteBuild)(extensionRoot, entrypoint, extensionDist);
78
+ function build({ extensionRoot, extensionDist, entrypoint, profileVariables, }) {
79
+ return (0, build_1.remoteBuild)({
80
+ root: extensionRoot,
81
+ entryPoint: entrypoint,
82
+ outputDir: extensionDist,
83
+ appConfig: {
84
+ variables: profileVariables,
85
+ },
86
+ });
79
87
  }
80
88
  // Mirrors: https://git.hubteam.com/HubSpot/Artifactor/blob/f5cbea91d7a7dfb6278e878ae583e69022384fb5/ArtifactorFunctions/functions/node_18x/uie-remote-build/index.js#L53-L57
81
89
  function installDeps(options) {
@@ -103,11 +111,26 @@ function getOptions(modulePath) {
103
111
  const extensionRoot = node_path_1.default.dirname(entrypoint);
104
112
  const extensionDist = node_path_1.default.join(extensionRoot, 'dist');
105
113
  const spinner = (0, ora_1.default)();
114
+ // The Artifactor changes related to this are not yet available.
115
+ // When it is, this will mirror the process where if applicable, a profile-variables.json file is available in the build bundle.
116
+ const programOptions = program.opts();
117
+ let profileVariables = {};
118
+ if (programOptions.profileVariables) {
119
+ const profileVariablePath = programOptions.profileVariables;
120
+ const profileVariableFullPath = node_path_1.default.isAbsolute(profileVariablePath)
121
+ ? profileVariablePath
122
+ : node_path_1.default.resolve(process.cwd(), profileVariablePath);
123
+ if (node_fs_1.default.existsSync(profileVariableFullPath) &&
124
+ node_path_1.default.extname(profileVariableFullPath) === '.json') {
125
+ profileVariables = JSON.parse(node_fs_1.default.readFileSync(profileVariableFullPath, 'utf-8'));
126
+ }
127
+ }
106
128
  return {
107
129
  extensionRoot,
108
130
  extensionDist,
109
131
  entrypoint,
110
132
  spinner,
133
+ profileVariables,
111
134
  };
112
135
  }
113
136
  function execAsync(command, options) {
@@ -1,4 +1,5 @@
1
1
  import { InlineConfig } from 'vite';
2
+ import { ManifestConfig } from './types';
2
3
  interface BuildSingleExtensionArgs {
3
4
  file: string;
4
5
  outputDir?: string;
@@ -6,9 +7,17 @@ interface BuildSingleExtensionArgs {
6
7
  minify?: boolean;
7
8
  root?: string;
8
9
  logLevel?: InlineConfig['logLevel'];
10
+ appConfig?: ManifestConfig;
11
+ }
12
+ interface RemoteBuildArgs {
13
+ root: string;
14
+ entryPoint: string;
15
+ outputDir?: string;
16
+ logLevel?: BuildSingleExtensionArgs['logLevel'];
17
+ appConfig?: ManifestConfig;
9
18
  }
10
19
  export declare const extensionErrorBaseMessage: string;
11
20
  export declare function buildSingleExtension({ file, outputDir, emptyOutDir, minify, root, // This is the vite default, so using that as our default
12
- logLevel, }: BuildSingleExtensionArgs): Promise<void>;
13
- export declare function remoteBuild(root: string, entryPoint: string, outputDir?: string, logLevel?: BuildSingleExtensionArgs['logLevel']): Promise<void>;
21
+ logLevel, appConfig, }: BuildSingleExtensionArgs): Promise<void>;
22
+ export declare function remoteBuild(args: RemoteBuildArgs): Promise<void>;
14
23
  export {};
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', appConfig, }) {
28
30
  const output = (0, utils_1.getUrlSafeFileName)(file);
29
31
  yield (0, vite_1.build)({
30
32
  logLevel,
@@ -40,7 +42,12 @@ logLevel = 'info', }) {
40
42
  fileName: () => output,
41
43
  },
42
44
  rollupOptions: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS), { plugins: [
43
- (0, manifestPlugin_1.default)({ output, extensionPath: root, logger: console }),
45
+ (0, manifestPlugin_1.default)({
46
+ output,
47
+ extensionPath: root,
48
+ logger: console,
49
+ manifestConfig: appConfig,
50
+ }),
44
51
  (0, friendlyLoggingPlugin_1.default)({ logger: console }),
45
52
  (0, codeBlockingPlugin_1.default)({ logger: console, extensionPath: root }),
46
53
  ] }),
@@ -51,9 +58,17 @@ logLevel = 'info', }) {
51
58
  });
52
59
  });
53
60
  }
54
- exports.buildSingleExtension = buildSingleExtension;
55
- function remoteBuild(root, entryPoint, outputDir = constants_1.OUTPUT_DIR, logLevel) {
61
+ function remoteBuild(args) {
56
62
  return __awaiter(this, void 0, void 0, function* () {
63
+ const { root, entryPoint, outputDir = constants_1.OUTPUT_DIR, logLevel, appConfig, } = args;
64
+ if (!root) {
65
+ console.error('remoteBuild Error: root is required');
66
+ return;
67
+ }
68
+ if (!entryPoint) {
69
+ console.error('remoteBuild Error: entryPoint is required');
70
+ return;
71
+ }
57
72
  const fileInfo = path_1.default.parse(entryPoint);
58
73
  if (!allowedExtensions.includes(fileInfo.ext)) {
59
74
  throw new Error(`${exports.extensionErrorBaseMessage} ${fileInfo.ext}`);
@@ -64,7 +79,7 @@ function remoteBuild(root, entryPoint, outputDir = constants_1.OUTPUT_DIR, logLe
64
79
  minify: true,
65
80
  root,
66
81
  logLevel,
82
+ appConfig,
67
83
  });
68
84
  });
69
85
  }
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;
@@ -23,13 +23,9 @@ class ExtensionsService {
23
23
  const output = path_1.default.parse(baseMessage.callback).name;
24
24
  return Object.assign(Object.assign({}, baseMessage), { manifest: (0, utils_1.loadManifest)(devServerState.outputDir, output) });
25
25
  });
26
- const response = {
27
- websocket: `ws://localhost:${devServerState.webSocketPort}`,
28
- version: constants_1.EXTENSIONS_MESSAGE_VERSION,
29
- capabilities,
30
- portalId: devServerState.portalId,
31
- extensions,
32
- };
26
+ const response = Object.assign({ websocket: `ws://localhost:${devServerState.webSocketPort}`, version: constants_1.EXTENSIONS_MESSAGE_VERSION, capabilities, portalId: devServerState.portalId, extensions }, (devServerState.functionsConfig.platformVersion && {
27
+ platformVersion: devServerState.functionsConfig.platformVersion,
28
+ }));
33
29
  res.status(200).json(response);
34
30
  }
35
31
  catch (e) {
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFunctionInvoked = exports.isIdentifierDefined = exports.isVariableImported = exports.getValueFromNode = void 0;
3
+ exports.getValueFromNode = getValueFromNode;
4
+ exports.isVariableImported = isVariableImported;
5
+ exports.isIdentifierDefined = isIdentifierDefined;
6
+ exports.isFunctionInvoked = isFunctionInvoked;
4
7
  /**
5
8
  * Extracts the value from a given AST node based on its type.
6
9
  * This function handles various node types such as Literal, Identifier (aka variables), ArrayExpression,
@@ -265,7 +268,6 @@ function getValueFromNode(node, state) {
265
268
  };
266
269
  }
267
270
  }
268
- exports.getValueFromNode = getValueFromNode;
269
271
  function isVariableImported(node, variableName) {
270
272
  if (!node) {
271
273
  return false;
@@ -276,7 +278,6 @@ function isVariableImported(node, variableName) {
276
278
  (node.type === 'ImportNamespaceSpecifier' &&
277
279
  node.local.name === variableName));
278
280
  }
279
- exports.isVariableImported = isVariableImported;
280
281
  function isIdentifierDefined(node, parent, name) {
281
282
  if (parent &&
282
283
  (parent.type === 'MemberExpression' || parent.type === 'CallExpression')) {
@@ -284,11 +285,9 @@ function isIdentifierDefined(node, parent, name) {
284
285
  }
285
286
  return node.type === 'Identifier' && node.name === name;
286
287
  }
287
- exports.isIdentifierDefined = isIdentifierDefined;
288
288
  function isFunctionInvoked(node, functionName) {
289
289
  return (node.type === 'CallExpression' &&
290
290
  node.callee &&
291
291
  'name' in node.callee &&
292
292
  node.callee.name === functionName);
293
293
  }
294
- exports.isFunctionInvoked = isFunctionInvoked;
@@ -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) {
@@ -49,6 +59,14 @@ const codeBlockingPlugin_1 = __importDefault(require("./codeBlockingPlugin"));
49
59
  function addVersionToBaseMessage(baseMessage) {
50
60
  return Object.assign(Object.assign({}, baseMessage), { version: constants_1.WEBSOCKET_MESSAGE_VERSION });
51
61
  }
62
+ function isValidVariablesRecord(obj) {
63
+ if (!obj || typeof obj !== 'object')
64
+ return false;
65
+ return Object.entries(obj).every(([key, value]) => typeof key === 'string' &&
66
+ (typeof value === 'string' ||
67
+ typeof value === 'number' ||
68
+ typeof value === 'boolean'));
69
+ }
52
70
  const devBuildPlugin = (options) => {
53
71
  const { devServerState } = options;
54
72
  const { logger } = devServerState;
@@ -68,10 +86,18 @@ const devBuildPlugin = (options) => {
68
86
  } }));
69
87
  }
70
88
  };
71
- const devBuild = (server, extensionMetadata, emptyOutDir = false) => __awaiter(void 0, void 0, void 0, function* () {
89
+ 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
90
  try {
73
91
  const { config: extensionConfig } = extensionMetadata;
74
92
  const { extensionPath } = extensionConfig;
93
+ let manifestConfig = {};
94
+ if (devServerState.appConfig &&
95
+ 'variables' in devServerState.appConfig &&
96
+ isValidVariablesRecord(devServerState.appConfig.variables)) {
97
+ manifestConfig = {
98
+ variables: devServerState.appConfig.variables,
99
+ };
100
+ }
75
101
  yield (0, vite_1.build)({
76
102
  logLevel: 'warn',
77
103
  mode: 'development',
@@ -98,6 +124,7 @@ const devBuildPlugin = (options) => {
98
124
  output: extensionConfig.output,
99
125
  extensionPath,
100
126
  logger,
127
+ manifestConfig,
101
128
  }),
102
129
  (0, codeCheckingPlugin_1.default)({
103
130
  output: path_1.default.join(devServerState.outputDir, extensionConfig.output),
@@ -151,7 +178,7 @@ const devBuildPlugin = (options) => {
151
178
  yield devBuild(localServer, devServerState.extensionsMetadata[i], i === 0);
152
179
  }
153
180
  }),
154
- handleHotUpdate: ({ file, server }) => __awaiter(void 0, void 0, void 0, function* () {
181
+ handleHotUpdate: (_a) => __awaiter(void 0, [_a], void 0, function* ({ file, server }) {
155
182
  // If the file is not in the relevantModules list, it's update is inconsequential
156
183
  const extensionsToRebuild = devServerState.extensionsMetadata.filter((metadata) => {
157
184
  const { config } = metadata;
@@ -1,10 +1,11 @@
1
1
  import { Rollup } from 'vite';
2
- import { Logger } from '../types';
2
+ import { Logger, ManifestConfig } from '../types';
3
3
  export interface ManifestPluginOptions {
4
4
  output: string;
5
5
  minify?: boolean;
6
6
  extensionPath?: string;
7
7
  logger: Logger;
8
+ manifestConfig?: ManifestConfig;
8
9
  }
9
10
  export type ManifestPlugin = (options: ManifestPluginOptions) => Rollup.Plugin;
10
11
  declare const manifestPlugin: ManifestPlugin;
@@ -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 = [];
@@ -47,7 +47,7 @@ const manifestPlugin = (options) => {
47
47
  const { output, minify = false, extensionPath = process.cwd(), logger, } = options;
48
48
  try {
49
49
  const filename = path_2.default.parse(output).name;
50
- const manifest = _generateManifestContents(bundle, extensionPath, allDataDependencies);
50
+ const manifest = _generateManifestContents(bundle, extensionPath, allDataDependencies, options === null || options === void 0 ? void 0 : options.manifestConfig);
51
51
  this.emitFile({
52
52
  type: 'asset',
53
53
  source: minify
@@ -62,22 +62,31 @@ const manifestPlugin = (options) => {
62
62
  },
63
63
  };
64
64
  };
65
- function _generateManifestContents(bundle, extensionPath, allDataDependencies) {
65
+ function _generateManifestContents(bundle, extensionPath, allDataDependencies, appConfig) {
66
66
  const baseManifest = {
67
67
  package: _loadPackageFile(extensionPath),
68
68
  };
69
69
  const dataDependencies = {
70
70
  dataDeps: allDataDependencies !== null && allDataDependencies !== void 0 ? allDataDependencies : [],
71
71
  };
72
+ const variables = {
73
+ variables: {},
74
+ };
75
+ if (appConfig &&
76
+ 'variables' in appConfig &&
77
+ typeof appConfig.variables === 'object' &&
78
+ appConfig.variables !== null) {
79
+ variables.variables = appConfig.variables;
80
+ }
72
81
  // The keys to bundle are the filename without any path information
73
82
  const bundles = Object.keys(bundle).filter((cur) => cur.endsWith('.js'));
74
83
  if (bundles.length === 1) {
75
- return Object.assign(Object.assign(Object.assign({}, _generateManifestEntry(bundle[bundles[0]], extensionPath)), dataDependencies), baseManifest);
84
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, _generateManifestEntry(bundle[bundles[0]], extensionPath)), dataDependencies), baseManifest), variables);
76
85
  }
77
86
  const manifest = bundles.reduce((acc, current) => {
78
87
  return Object.assign(Object.assign({}, acc), { [current]: _generateManifestEntry(bundle[current], extensionPath) });
79
88
  }, {});
80
- return Object.assign(Object.assign(Object.assign({}, manifest), dataDependencies), baseManifest);
89
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, manifest), dataDependencies), baseManifest), variables);
81
90
  }
82
91
  function _generateManifestEntry(subBundle, extensionPath) {
83
92
  const { facadeModuleId, moduleIds, modules } = subBundle;
@@ -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
  });
@@ -163,6 +163,9 @@ export interface UnifiedAppComponent {
163
163
  supportUrl: string;
164
164
  supportPhone: string;
165
165
  };
166
+ variables?: {
167
+ [key: string]: string | number | boolean;
168
+ };
166
169
  };
167
170
  componentType: UnifiedComponentTypes.APPLICATION;
168
171
  componentDeps: {};
@@ -176,6 +179,9 @@ export interface UnifiedAppComponent {
176
179
  export type UnifiedAppConfig = Omit<PublicAppConfig, 'auth'> & {
177
180
  auth: UnifiedAppAuth;
178
181
  isPublicApp: boolean;
182
+ variables?: {
183
+ [key: string]: string | number | boolean;
184
+ };
179
185
  };
180
186
  export type UnifiedComponent = UnifiedExtensionComponent | UnifiedAppComponent;
181
187
  export interface UnifiedProjectComponentMap {
@@ -274,5 +280,11 @@ export interface DevModeSetupArguments extends DevModeBaseSetupArguments {
274
280
  }
275
281
  export interface UnifiedDevModeSetupArguments extends DevModeBaseSetupArguments {
276
282
  components: UnifiedProjectComponentMap;
283
+ profileData?: ProfileVariables;
284
+ }
285
+ export type ProfileVariableValue = string | number | boolean;
286
+ export type ProfileVariables = Record<string, ProfileVariableValue>;
287
+ export interface ManifestConfig {
288
+ variables?: ProfileVariables;
277
289
  }
278
290
  export {};
package/dist/lib/utils.js CHANGED
@@ -3,7 +3,17 @@ 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
19
  const constants_1 = require("./constants");
@@ -11,7 +21,6 @@ function getUrlSafeFileName(filePath) {
11
21
  const { name } = path_1.default.parse(filePath);
12
22
  return encodeURIComponent(`${name}.js`);
13
23
  }
14
- exports.getUrlSafeFileName = getUrlSafeFileName;
15
24
  // Strips ANSI color codes out of strings because we don't want to pass them to the browser
16
25
  function stripAnsiColorCodes(stringWithColorCodes) {
17
26
  if (!stringWithColorCodes) {
@@ -21,7 +30,6 @@ function stripAnsiColorCodes(stringWithColorCodes) {
21
30
  // eslint-disable-next-line no-control-regex
22
31
  /[\u001b][[]*([0-9]{1,4};?)*[m]/g, '');
23
32
  }
24
- exports.stripAnsiColorCodes = stripAnsiColorCodes;
25
33
  function loadManifest(outputDir, output) {
26
34
  try {
27
35
  return JSON.parse(fs_1.default
@@ -32,14 +40,12 @@ function loadManifest(outputDir, output) {
32
40
  return {};
33
41
  }
34
42
  }
35
- exports.loadManifest = loadManifest;
36
43
  function buildSourceId(appConfig, extensionConfig) {
37
44
  if (appConfig.uid && extensionConfig.data.uid) {
38
45
  return `${appConfig.uid}::${extensionConfig.data.uid}`;
39
46
  }
40
47
  return null;
41
48
  }
42
- exports.buildSourceId = buildSourceId;
43
49
  function isNodeModule(filepath) {
44
50
  if (!filepath) {
45
51
  return false;
@@ -47,7 +53,6 @@ function isNodeModule(filepath) {
47
53
  const directory = path_1.default.parse(filepath).dir;
48
54
  return directory.includes('node_modules');
49
55
  }
50
- exports.isNodeModule = isNodeModule;
51
56
  /**
52
57
  * Check if a given file is within the extension path
53
58
  */
@@ -67,7 +72,6 @@ function isExtensionFile(filepath, extensionPath) {
67
72
  return false;
68
73
  }
69
74
  }
70
- exports.isExtensionFile = isExtensionFile;
71
75
  class UnhandledPlatformVersionError extends Error {
72
76
  constructor(platformVersion) {
73
77
  super(`Unsupported platform version "${platformVersion}"`);
@@ -77,14 +81,12 @@ exports.UnhandledPlatformVersionError = UnhandledPlatformVersionError;
77
81
  function throwUnhandledPlatformVersionError(platformVersion) {
78
82
  throw new UnhandledPlatformVersionError(platformVersion);
79
83
  }
80
- exports.throwUnhandledPlatformVersionError = throwUnhandledPlatformVersionError;
81
84
  function extractAllowedUrls(appConfig) {
82
85
  if (!appConfig || !('allowedUrls' in appConfig) || !appConfig.allowedUrls) {
83
86
  return [];
84
87
  }
85
88
  return appConfig.allowedUrls;
86
89
  }
87
- exports.extractAllowedUrls = extractAllowedUrls;
88
90
  function simpleHash(input) {
89
91
  let hash = 0;
90
92
  for (let i = 0; i < input.length; i++) {
@@ -120,11 +122,9 @@ function generateHash(...args) {
120
122
  return '';
121
123
  }
122
124
  }
123
- exports.generateHash = generateHash;
124
125
  /**
125
126
  * Check if a given URL is an image (of a type we support)
126
127
  */
127
128
  function isImage(url) {
128
129
  return /\.(png|jpg|jpeg|gif|svg|webp|avif|raw|url|inline)$/.test(url);
129
130
  }
130
- 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.8",
3
+ "version": "0.10.1",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "uie": "./dist/lib/bin/cli.js"
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@hubspot/app-functions-dev-server": "0.9.2",
30
+ "@hubspot/app-functions-dev-server": "0.10.1",
31
31
  "body-parser": "1.20.3",
32
32
  "chalk": "5.4.1",
33
33
  "commander": "13.0.0",
@@ -49,7 +49,7 @@
49
49
  "axios": "1.6.8",
50
50
  "jest": "^29.5.0",
51
51
  "ts-jest": "^29.1.1",
52
- "typescript": "^5.1.6",
52
+ "typescript": "^5.9.2",
53
53
  "ws": "^8.13.0"
54
54
  },
55
55
  "eslintConfig": {
@@ -70,5 +70,5 @@
70
70
  "optional": true
71
71
  }
72
72
  },
73
- "gitHead": "68d176099343d6d202421ec241c131f1d07562a8"
73
+ "gitHead": "d3300e12daf61bc1931da0e79d62aede9675a750"
74
74
  }