@hubspot/ui-extensions-dev-server 0.8.12 → 0.8.14

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.
@@ -124,6 +124,7 @@ class DevModeInterface {
124
124
  });
125
125
  }
126
126
  start({ requestPorts, accountId, projectConfig }) {
127
+ var _a, _b, _c, _d;
127
128
  return __awaiter(this, void 0, void 0, function* () {
128
129
  this.logger.debug('Start function was invoked', {
129
130
  accountId,
@@ -148,7 +149,9 @@ class DevModeInterface {
148
149
  this.logger.debug('Call to port manager failed, using default ports');
149
150
  }
150
151
  }
152
+ 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) || '') || {};
151
153
  this.devServerState = new DevServerState_1.DevServerState({
154
+ localDevUrlMapping,
152
155
  extensionConfigs: this.configs,
153
156
  accountId,
154
157
  platformVersion: this._getPlatformVersion(projectConfig),
@@ -156,6 +159,7 @@ class DevModeInterface {
156
159
  webSocketPort,
157
160
  logger: this.logger,
158
161
  urls: this.urls,
162
+ appConfig: (_d = (_c = this.configs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.appConfig,
159
163
  });
160
164
  this.shutdown = yield (0, dev_1.startDevMode)(this.devServerState);
161
165
  const { extensionsMetadata } = this.devServerState;
@@ -1,6 +1,8 @@
1
- import { ExtensionConfig, ExtensionMetadata, Logger, PlatformVersion } from './types';
2
- import { ServiceConfiguration } from '@hubspot/app-functions-dev-server/dist/types';
1
+ import { AppConfig, ExtensionConfig, ExtensionMetadata, Logger, PlatformVersion } from './types';
2
+ import { ServiceConfiguration, ProxyServiceConfig } from '@hubspot/app-functions-dev-server';
3
+ type DevServerStateLocalDevUrlMapping = ProxyServiceConfig['localDevUrlMapping'] | undefined;
3
4
  interface DevServerStateArgs {
5
+ localDevUrlMapping?: DevServerStateLocalDevUrlMapping;
4
6
  extensionConfigs?: ExtensionConfig[];
5
7
  accountId: number | undefined;
6
8
  expressPort: number;
@@ -11,17 +13,20 @@ interface DevServerStateArgs {
11
13
  api: string;
12
14
  web: string;
13
15
  };
16
+ appConfig?: AppConfig;
14
17
  }
15
18
  export declare class DevServerState {
16
19
  private _webSocketPort;
17
20
  private _expressPort;
18
21
  private _functionsConfig;
22
+ private _localDevUrlMapping;
19
23
  private _outputDir;
20
24
  private _appPath;
21
25
  private _extensionsMetadata;
22
26
  private _portalId?;
23
27
  logger: Logger;
24
- constructor({ extensionConfigs, accountId, expressPort, webSocketPort, platformVersion, logger, urls, }: DevServerStateArgs);
28
+ appConfig?: AppConfig;
29
+ constructor({ localDevUrlMapping, extensionConfigs, accountId, expressPort, webSocketPort, platformVersion, logger, urls, appConfig, }: DevServerStateArgs);
25
30
  get portalId(): number | undefined;
26
31
  get webSocketPort(): number;
27
32
  get expressPort(): number;
@@ -29,5 +34,6 @@ export declare class DevServerState {
29
34
  get functionsConfig(): Partial<ServiceConfiguration>;
30
35
  get outputDir(): string;
31
36
  get appPath(): string;
37
+ get localDevUrlMapping(): DevServerStateLocalDevUrlMapping;
32
38
  }
33
39
  export {};
@@ -7,7 +7,7 @@ exports.DevServerState = void 0;
7
7
  const constants_1 = require("./constants");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  class DevServerState {
10
- constructor({ extensionConfigs, accountId, expressPort, webSocketPort, platformVersion, logger, urls, }) {
10
+ constructor({ localDevUrlMapping, extensionConfigs, accountId, expressPort, webSocketPort, platformVersion, logger, urls, appConfig, }) {
11
11
  if (!extensionConfigs) {
12
12
  throw new Error('Unable to load the required extension configuration files');
13
13
  }
@@ -39,7 +39,9 @@ class DevServerState {
39
39
  hubspotApiOrigin: urls.api,
40
40
  hubspotWebsiteOrigin: urls.web,
41
41
  };
42
+ this._localDevUrlMapping = localDevUrlMapping;
42
43
  this.logger = logger;
44
+ this.appConfig = appConfig;
43
45
  Object.freeze(this);
44
46
  }
45
47
  get portalId() {
@@ -63,5 +65,8 @@ class DevServerState {
63
65
  get appPath() {
64
66
  return this._appPath;
65
67
  }
68
+ get localDevUrlMapping() {
69
+ return this._localDevUrlMapping;
70
+ }
66
71
  }
67
72
  exports.DevServerState = DevServerState;
@@ -1,3 +1,4 @@
1
- import { AppConfig, ExtensionConfigMap } from './types';
1
+ import { AppConfig, ExtensionConfigMap, LocalAppConfig } from './types';
2
2
  export declare function loadConfigByPath<T = unknown>(configPath: string): T;
3
3
  export declare function loadExtensionConfig(appConfig: AppConfig, appPath: string): ExtensionConfigMap;
4
+ export declare function loadLocalConfig(appPath: string): LocalAppConfig | undefined;
@@ -5,7 +5,7 @@ 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.loadExtensionConfig = exports.loadConfigByPath = void 0;
8
+ exports.loadLocalConfig = exports.loadExtensionConfig = exports.loadConfigByPath = void 0;
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const utils_1 = require("./utils");
@@ -28,7 +28,7 @@ function loadExtensionConfig(appConfig, appPath) {
28
28
  const entryPointPath = path_1.default.join(cardConfigDir, (_b = (_a = cardConfig.data) === null || _a === void 0 ? void 0 : _a.module) === null || _b === void 0 ? void 0 : _b.file);
29
29
  cardConfig.data.module.file = entryPointPath;
30
30
  const sourceId = (0, utils_1.buildSourceId)(appConfig, cardConfig);
31
- outputConfig[sourceId || `${entryPointPath}-${cardConfig.data.location}`] = Object.assign(Object.assign({}, cardConfig), { output: (0, utils_1.getUrlSafeFileName)(entryPointPath), path: appPath, extensionPath: path_1.default.parse(entryPointPath).dir, extensionConfigPath: cardConfigPath, data: Object.assign(Object.assign({}, cardConfig.data), { appName: appConfig.name, sourceId }) });
31
+ outputConfig[sourceId || `${entryPointPath}-${cardConfig.data.location}`] = Object.assign(Object.assign({}, cardConfig), { output: (0, utils_1.getUrlSafeFileName)(entryPointPath), path: appPath, extensionPath: path_1.default.parse(entryPointPath).dir, extensionConfigPath: cardConfigPath, data: Object.assign(Object.assign({}, cardConfig.data), { appName: appConfig.name, sourceId }), appConfig });
32
32
  }
33
33
  }
34
34
  catch (e) {
@@ -38,3 +38,16 @@ function loadExtensionConfig(appConfig, appPath) {
38
38
  return outputConfig;
39
39
  }
40
40
  exports.loadExtensionConfig = loadExtensionConfig;
41
+ function loadLocalConfig(appPath) {
42
+ try {
43
+ const localConfig = path_1.default.join(appPath, 'local.json');
44
+ if (fs_1.default.existsSync(localConfig)) {
45
+ return JSON.parse(fs_1.default.readFileSync(localConfig).toString());
46
+ }
47
+ }
48
+ catch (e) {
49
+ return undefined;
50
+ }
51
+ return undefined;
52
+ }
53
+ exports.loadLocalConfig = loadLocalConfig;
@@ -16,6 +16,7 @@ export declare const ROLLUP_OPTIONS: {
16
16
  };
17
17
  export declare const EXTENSIONS_MESSAGE_VERSION = 2;
18
18
  export declare const WEBSOCKET_MESSAGE_VERSION = 1;
19
+ export declare const PROXY_CAPABILITY = "app-backend-proxy-server";
19
20
  export declare const SERVER_CAPABILITIES: string[];
20
21
  export declare const PLATFORM_VERSION: {
21
22
  readonly V20231: "2023.1";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUPPORTED_APP_TYPES = exports.PRIVATE_APP = exports.PUBLIC_APP = exports.PLATFORM_VERSION = exports.SERVER_CAPABILITIES = exports.WEBSOCKET_MESSAGE_VERSION = exports.EXTENSIONS_MESSAGE_VERSION = exports.ROLLUP_OPTIONS = exports.WEBSOCKET_DEFAULT_PORT = exports.EXPRESS_DEFAULT_PORT = exports.VITE_DEV_SERVER_ID = exports.EXPRESS_SERVER_ID = exports.MANIFEST_FILE = exports.OUTPUT_DIR = void 0;
3
+ exports.SUPPORTED_APP_TYPES = exports.PRIVATE_APP = exports.PUBLIC_APP = exports.PLATFORM_VERSION = exports.SERVER_CAPABILITIES = exports.PROXY_CAPABILITY = exports.WEBSOCKET_MESSAGE_VERSION = exports.EXTENSIONS_MESSAGE_VERSION = exports.ROLLUP_OPTIONS = exports.WEBSOCKET_DEFAULT_PORT = exports.EXPRESS_DEFAULT_PORT = exports.VITE_DEV_SERVER_ID = exports.EXPRESS_SERVER_ID = exports.MANIFEST_FILE = exports.OUTPUT_DIR = void 0;
4
4
  exports.OUTPUT_DIR = 'dist';
5
5
  exports.MANIFEST_FILE = 'manifest.json';
6
6
  exports.EXPRESS_SERVER_ID = 'ui-extensions-dev-server';
@@ -21,6 +21,7 @@ exports.ROLLUP_OPTIONS = {
21
21
  };
22
22
  exports.EXTENSIONS_MESSAGE_VERSION = 2;
23
23
  exports.WEBSOCKET_MESSAGE_VERSION = 1;
24
+ exports.PROXY_CAPABILITY = 'app-backend-proxy-server';
24
25
  exports.SERVER_CAPABILITIES = [
25
26
  // Supports running app functions locally
26
27
  'app-functions-local-dev',
@@ -19,6 +19,7 @@ const cors_1 = __importDefault(require("cors"));
19
19
  const constants_1 = require("./constants");
20
20
  const extensionsService_1 = __importDefault(require("./extensionsService"));
21
21
  const app_functions_dev_server_1 = require("@hubspot/app-functions-dev-server");
22
+ const utils_1 = require("./utils");
22
23
  function listen(app, port) {
23
24
  return new Promise((resolve, reject) => {
24
25
  const server = app
@@ -37,9 +38,23 @@ function startDevServer({ devServerState, viteDevServer, }) {
37
38
  // Setup middleware
38
39
  app.use((0, cors_1.default)());
39
40
  app.use(express_1.default.static(devServerState.outputDir));
40
- app.use('/api/crm-extensibility/execution/internal/v3', (0, app_functions_dev_server_1.AppFunctionExecutionService)(Object.assign(Object.assign({}, devServerState.functionsConfig), { logger: devServerState.logger })));
41
+ const capabilities = [...constants_1.SERVER_CAPABILITIES];
42
+ const middlewares = [
43
+ (0, app_functions_dev_server_1.AppFunctionExecutionService)(Object.assign(Object.assign({}, devServerState.functionsConfig), { logger: devServerState.logger })),
44
+ ];
45
+ if (devServerState.localDevUrlMapping) {
46
+ devServerState.logger.info('Proxy config discovered, enabling local proxy mode');
47
+ middlewares.push((0, app_functions_dev_server_1.AppProxyService)({
48
+ localDevUrlMapping: devServerState.localDevUrlMapping,
49
+ logger: devServerState.logger,
50
+ accountId: devServerState.functionsConfig.accountId,
51
+ allowedUrls: (0, utils_1.extractAllowedUrls)(devServerState.appConfig),
52
+ }));
53
+ capabilities.push(constants_1.PROXY_CAPABILITY);
54
+ }
55
+ app.use('/api/crm-extensibility/execution/internal/v3', ...middlewares);
41
56
  devServerState.logger.info(`Serving app functions locally (platform version ${devServerState.functionsConfig.platformVersion})`);
42
- const endpointsAdded = extensionsService_1.default.add(app, devServerState, constants_1.SERVER_CAPABILITIES);
57
+ const endpointsAdded = extensionsService_1.default.add(app, devServerState, capabilities);
43
58
  const { expressPort } = devServerState;
44
59
  endpointsAdded.forEach((endpoint) => {
45
60
  devServerState.logger.debug(`Listening at http://hslocal.net:${expressPort}${endpoint}`);
@@ -1,4 +1,5 @@
1
1
  import { PLATFORM_VERSION, PRIVATE_APP, PUBLIC_APP } from './constants';
2
+ import { LocalDevUrlMapping } from '@hubspot/app-functions-dev-server';
2
3
  export interface ObjectTypes {
3
4
  name: string;
4
5
  }
@@ -19,6 +20,7 @@ export interface ExtensionConfig {
19
20
  sourceId?: string | null;
20
21
  };
21
22
  uid?: string;
23
+ appConfig?: AppConfig;
22
24
  }
23
25
  export interface ExtensionConfigMap {
24
26
  [key: string]: ExtensionConfig;
@@ -43,12 +45,15 @@ export interface PrivateAppConfig {
43
45
  };
44
46
  uid?: string;
45
47
  }
48
+ export interface LocalAppConfig {
49
+ proxy: LocalDevUrlMapping;
50
+ }
46
51
  export interface PublicAppConfig {
47
52
  name: string;
48
53
  uid: string;
49
54
  logo?: string;
50
55
  description?: string;
51
- allowedExternalUrls?: string[];
56
+ allowedUrls?: string[];
52
57
  auth?: {
53
58
  preventAdditionalScopes: boolean;
54
59
  preventOptionalScopes: boolean;
@@ -8,3 +8,4 @@ export declare class UnhandledPlatformVersionError extends Error {
8
8
  constructor(platformVersion: never);
9
9
  }
10
10
  export declare function throwUnhandledPlatformVersionError(platformVersion: never): never;
11
+ export declare function extractAllowedUrls(appConfig?: AppConfig): string[];
package/dist/lib/utils.js CHANGED
@@ -3,7 +3,7 @@ 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.throwUnhandledPlatformVersionError = exports.UnhandledPlatformVersionError = exports.isNodeModule = exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
6
+ exports.extractAllowedUrls = exports.throwUnhandledPlatformVersionError = exports.UnhandledPlatformVersionError = exports.isNodeModule = exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const constants_1 = require("./constants");
@@ -58,3 +58,10 @@ function throwUnhandledPlatformVersionError(platformVersion) {
58
58
  throw new UnhandledPlatformVersionError(platformVersion);
59
59
  }
60
60
  exports.throwUnhandledPlatformVersionError = throwUnhandledPlatformVersionError;
61
+ function extractAllowedUrls(appConfig) {
62
+ if (!appConfig || !('allowedUrls' in appConfig) || !appConfig.allowedUrls) {
63
+ return [];
64
+ }
65
+ return appConfig.allowedUrls;
66
+ }
67
+ exports.extractAllowedUrls = extractAllowedUrls;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.8.12",
3
+ "version": "0.8.14",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@hubspot/app-functions-dev-server": "^0.8.11",
29
+ "@hubspot/app-functions-dev-server": "^0.8.14",
30
30
  "cors": "^2.8.5",
31
31
  "detect-port": "1.5.1",
32
32
  "estraverse": "^5.3.0",
@@ -64,5 +64,5 @@
64
64
  "optional": true
65
65
  }
66
66
  },
67
- "gitHead": "de63cea5e941c10de794210c1a095ae2468d6a9d"
67
+ "gitHead": "1850d1e7967463bfec84fddaa9d5b167a76b55a7"
68
68
  }