@hubspot/ui-extensions-dev-server 0.8.11 → 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.
- package/dist/lib/DevModeInterface.d.ts +4 -8
- package/dist/lib/DevModeInterface.js +26 -10
- package/dist/lib/DevServerState.d.ts +9 -3
- package/dist/lib/DevServerState.js +6 -1
- package/dist/lib/build.js +1 -1
- package/dist/lib/config.d.ts +2 -1
- package/dist/lib/config.js +15 -2
- package/dist/lib/constants.d.ts +4 -1
- package/dist/lib/constants.js +7 -2
- package/dist/lib/plugins/devBuildPlugin.js +1 -0
- package/dist/lib/plugins/manifestPlugin.d.ts +2 -0
- package/dist/lib/plugins/manifestPlugin.js +2 -4
- package/dist/lib/server.js +17 -2
- package/dist/lib/types.d.ts +40 -2
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +8 -1
- package/package.json +7 -10
- package/dist/lib/plugins/codeInjectionPlugin.d.ts +0 -8
- package/dist/lib/plugins/codeInjectionPlugin.js +0 -30
- package/dist/lib/self.d.ts +0 -0
- package/dist/lib/self.js +0 -4
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExtensionConfig, Logger, PlatformVersion, ProjectComponentMap, ProjectConfig } from './types';
|
|
2
2
|
import { PromptModule } from 'inquirer';
|
|
3
3
|
import { DevServerState } from './DevServerState';
|
|
4
4
|
interface SetupArguments {
|
|
5
5
|
components: ProjectComponentMap;
|
|
6
|
-
extensionConfig?: ExtensionConfig;
|
|
7
6
|
onUploadRequired?: VoidFunction;
|
|
8
7
|
promptUser: PromptModule;
|
|
9
8
|
logger: Logger;
|
|
@@ -12,11 +11,6 @@ interface SetupArguments {
|
|
|
12
11
|
web: string;
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
|
-
interface ProjectConfig {
|
|
16
|
-
name: string;
|
|
17
|
-
srcDir: string;
|
|
18
|
-
platformVersion?: PlatformVersion;
|
|
19
|
-
}
|
|
20
14
|
interface StartArguments {
|
|
21
15
|
accountId?: number;
|
|
22
16
|
requestPorts?: (requestPortsData: Array<{
|
|
@@ -38,9 +32,11 @@ declare class DevModeInterface {
|
|
|
38
32
|
shutdown?: () => Promise<void>;
|
|
39
33
|
logger: Logger;
|
|
40
34
|
urls?: SetupArguments['urls'];
|
|
35
|
+
isConfigured?: boolean;
|
|
36
|
+
isRunning?: boolean;
|
|
41
37
|
_generateAppExtensionMappings(components: ProjectComponentMap): AppExtensionMapping[];
|
|
42
38
|
_getPlatformVersion(projectConfig?: ProjectConfig): PlatformVersion;
|
|
43
|
-
setup({ components,
|
|
39
|
+
setup({ components, onUploadRequired, promptUser, logger, urls, }: SetupArguments): Promise<void>;
|
|
44
40
|
fileChange(filePath: string, __event: unknown): Promise<void>;
|
|
45
41
|
start({ requestPorts, accountId, projectConfig }: StartArguments): Promise<void>;
|
|
46
42
|
cleanup(): Promise<void>;
|
|
@@ -39,10 +39,9 @@ class DevModeInterface {
|
|
|
39
39
|
// Loop over all of the app configs that are passed in
|
|
40
40
|
const allComponentNames = Object.keys(components);
|
|
41
41
|
return allComponentNames.reduce((appExtensionMappings, componentName) => {
|
|
42
|
-
var _a, _b;
|
|
43
42
|
const component = components[componentName];
|
|
44
|
-
if (!(
|
|
45
|
-
return appExtensionMappings; // It's not
|
|
43
|
+
if (!constants_1.SUPPORTED_APP_TYPES.includes(component.type)) {
|
|
44
|
+
return appExtensionMappings; // It's not a modern app, skip it
|
|
46
45
|
}
|
|
47
46
|
// Load all of the extension configs for a particular app.json file
|
|
48
47
|
const extensionsConfigForApp = (0, config_1.loadExtensionConfig)(component.config, component.path);
|
|
@@ -72,15 +71,16 @@ class DevModeInterface {
|
|
|
72
71
|
return (0, utils_1.throwUnhandledPlatformVersionError)(platformVersion);
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
|
-
setup({ components,
|
|
74
|
+
setup({ components, onUploadRequired, promptUser, logger, urls, }) {
|
|
76
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
logger.debug('Setup function was invoked', { components, urls });
|
|
77
|
+
if (this.isConfigured) {
|
|
78
|
+
logger.debug('Dev server has already been configured, skipping');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
77
81
|
this.logger = logger;
|
|
78
82
|
this.onUploadRequired = onUploadRequired;
|
|
79
83
|
this.urls = urls;
|
|
80
|
-
if (extensionConfig) {
|
|
81
|
-
this.configs = [extensionConfig];
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
84
|
const choices = this._generateAppExtensionMappings(components);
|
|
85
85
|
if (choices.length === 0) {
|
|
86
86
|
throw new Error('No extensions to run');
|
|
@@ -107,6 +107,7 @@ class DevModeInterface {
|
|
|
107
107
|
});
|
|
108
108
|
this.configs = answers.extensions;
|
|
109
109
|
}
|
|
110
|
+
this.isConfigured = true;
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
// The contract is for this to be async, so eslint can chill
|
|
@@ -123,7 +124,16 @@ class DevModeInterface {
|
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
126
|
start({ requestPorts, accountId, projectConfig }) {
|
|
127
|
+
var _a, _b, _c, _d;
|
|
126
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
this.logger.debug('Start function was invoked', {
|
|
130
|
+
accountId,
|
|
131
|
+
projectConfig,
|
|
132
|
+
});
|
|
133
|
+
if (this.isRunning) {
|
|
134
|
+
this.logger.debug('Dev server is already running, not starting again');
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
127
137
|
let expressPort = constants_1.EXPRESS_DEFAULT_PORT;
|
|
128
138
|
let webSocketPort = constants_1.WEBSOCKET_DEFAULT_PORT;
|
|
129
139
|
if (requestPorts) {
|
|
@@ -139,7 +149,9 @@ class DevModeInterface {
|
|
|
139
149
|
this.logger.debug('Call to port manager failed, using default ports');
|
|
140
150
|
}
|
|
141
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) || '') || {};
|
|
142
153
|
this.devServerState = new DevServerState_1.DevServerState({
|
|
154
|
+
localDevUrlMapping,
|
|
143
155
|
extensionConfigs: this.configs,
|
|
144
156
|
accountId,
|
|
145
157
|
platformVersion: this._getPlatformVersion(projectConfig),
|
|
@@ -147,18 +159,22 @@ class DevModeInterface {
|
|
|
147
159
|
webSocketPort,
|
|
148
160
|
logger: this.logger,
|
|
149
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,
|
|
150
163
|
});
|
|
151
164
|
this.shutdown = yield (0, dev_1.startDevMode)(this.devServerState);
|
|
152
|
-
this.devServerState
|
|
165
|
+
const { extensionsMetadata } = this.devServerState;
|
|
166
|
+
extensionsMetadata.forEach((metadata) => {
|
|
153
167
|
const { config: { data: { title, appName }, }, } = metadata;
|
|
154
168
|
this.logger.info(`Running extension '${title}' from app '${appName}'`);
|
|
155
169
|
});
|
|
170
|
+
this.isRunning = true;
|
|
156
171
|
});
|
|
157
172
|
}
|
|
158
173
|
cleanup() {
|
|
159
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
if (this.shutdown) {
|
|
175
|
+
if (this.shutdown && this.isRunning) {
|
|
161
176
|
yield this.shutdown();
|
|
177
|
+
this.isRunning = false;
|
|
162
178
|
}
|
|
163
179
|
});
|
|
164
180
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ExtensionConfig, ExtensionMetadata, Logger, PlatformVersion } from './types';
|
|
2
|
-
import { ServiceConfiguration } from '@hubspot/app-functions-dev-server
|
|
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
|
-
|
|
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;
|
package/dist/lib/build.js
CHANGED
|
@@ -39,7 +39,7 @@ function buildSingleExtension({ file, outputDir = constants_1.OUTPUT_DIR, emptyO
|
|
|
39
39
|
fileName: () => output,
|
|
40
40
|
},
|
|
41
41
|
rollupOptions: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS), { plugins: [
|
|
42
|
-
(0, manifestPlugin_1.default)({ output, extensionPath: root }),
|
|
42
|
+
(0, manifestPlugin_1.default)({ output, extensionPath: root, logger: console }),
|
|
43
43
|
(0, friendlyLoggingPlugin_1.default)({ logger: console }),
|
|
44
44
|
(0, codeBlockingPlugin_1.default)({ logger: console }),
|
|
45
45
|
] }),
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -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;
|
package/dist/lib/config.js
CHANGED
|
@@ -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;
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const OUTPUT_DIR = "dist";
|
|
2
|
-
export declare const MAIN_APP_CONFIG = "app.json";
|
|
3
2
|
export declare const MANIFEST_FILE = "manifest.json";
|
|
4
3
|
export declare const EXPRESS_SERVER_ID = "ui-extensions-dev-server";
|
|
5
4
|
export declare const VITE_DEV_SERVER_ID = "ui-extensions-vite-dev-server";
|
|
@@ -17,8 +16,12 @@ export declare const ROLLUP_OPTIONS: {
|
|
|
17
16
|
};
|
|
18
17
|
export declare const EXTENSIONS_MESSAGE_VERSION = 2;
|
|
19
18
|
export declare const WEBSOCKET_MESSAGE_VERSION = 1;
|
|
19
|
+
export declare const PROXY_CAPABILITY = "app-backend-proxy-server";
|
|
20
20
|
export declare const SERVER_CAPABILITIES: string[];
|
|
21
21
|
export declare const PLATFORM_VERSION: {
|
|
22
22
|
readonly V20231: "2023.1";
|
|
23
23
|
readonly V20232: "2023.2";
|
|
24
24
|
};
|
|
25
|
+
export declare const PUBLIC_APP = "public-app";
|
|
26
|
+
export declare const PRIVATE_APP = "private-app";
|
|
27
|
+
export declare const SUPPORTED_APP_TYPES: string[];
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.
|
|
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
|
-
exports.MAIN_APP_CONFIG = 'app.json';
|
|
6
5
|
exports.MANIFEST_FILE = 'manifest.json';
|
|
7
6
|
exports.EXPRESS_SERVER_ID = 'ui-extensions-dev-server';
|
|
8
7
|
exports.VITE_DEV_SERVER_ID = 'ui-extensions-vite-dev-server';
|
|
@@ -22,6 +21,7 @@ exports.ROLLUP_OPTIONS = {
|
|
|
22
21
|
};
|
|
23
22
|
exports.EXTENSIONS_MESSAGE_VERSION = 2;
|
|
24
23
|
exports.WEBSOCKET_MESSAGE_VERSION = 1;
|
|
24
|
+
exports.PROXY_CAPABILITY = 'app-backend-proxy-server';
|
|
25
25
|
exports.SERVER_CAPABILITIES = [
|
|
26
26
|
// Supports running app functions locally
|
|
27
27
|
'app-functions-local-dev',
|
|
@@ -32,3 +32,8 @@ exports.PLATFORM_VERSION = {
|
|
|
32
32
|
V20231: '2023.1',
|
|
33
33
|
V20232: '2023.2',
|
|
34
34
|
};
|
|
35
|
+
exports.PUBLIC_APP = 'public-app';
|
|
36
|
+
// You gotta be kidding me linter
|
|
37
|
+
// eslint-disable-next-line hubspot-dev/no-private-classes
|
|
38
|
+
exports.PRIVATE_APP = 'private-app';
|
|
39
|
+
exports.SUPPORTED_APP_TYPES = [exports.PUBLIC_APP, exports.PRIVATE_APP];
|
|
@@ -96,6 +96,7 @@ const devBuildPlugin = (options) => {
|
|
|
96
96
|
minify: false,
|
|
97
97
|
output: extensionConfig.output,
|
|
98
98
|
extensionPath: extensionConfig.extensionPath,
|
|
99
|
+
logger,
|
|
99
100
|
}),
|
|
100
101
|
(0, codeCheckingPlugin_1.default)({
|
|
101
102
|
output: path_1.default.join(devServerState.outputDir, extensionConfig.output),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Rollup } from 'vite';
|
|
2
|
+
import { Logger } from '../types';
|
|
2
3
|
export interface ManifestPluginOptions {
|
|
3
4
|
output: string;
|
|
4
5
|
minify?: boolean;
|
|
5
6
|
extensionPath?: string;
|
|
7
|
+
logger: Logger;
|
|
6
8
|
}
|
|
7
9
|
export type ManifestPlugin = (options: ManifestPluginOptions) => Rollup.Plugin;
|
|
8
10
|
declare const manifestPlugin: ManifestPlugin;
|
|
@@ -9,8 +9,6 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const constants_1 = require("../constants");
|
|
11
11
|
const path_2 = __importDefault(require("path"));
|
|
12
|
-
// @ts-expect-error no type defs for the logger
|
|
13
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
14
12
|
const utils_1 = require("../utils");
|
|
15
13
|
const PACKAGE_LOCK_FILE = 'package-lock.json';
|
|
16
14
|
const PACKAGE_FILE = 'package.json';
|
|
@@ -20,7 +18,7 @@ const manifestPlugin = (options) => {
|
|
|
20
18
|
name: 'ui-extensions-manifest-generation-plugin',
|
|
21
19
|
enforce: 'post',
|
|
22
20
|
generateBundle(_rollupOptions, bundle) {
|
|
23
|
-
const { output, minify = false, extensionPath = process.cwd() } = options;
|
|
21
|
+
const { output, minify = false, extensionPath = process.cwd(), logger, } = options;
|
|
24
22
|
try {
|
|
25
23
|
const filename = path_2.default.parse(output).name;
|
|
26
24
|
const manifest = _generateManifestContents(bundle, extensionPath);
|
|
@@ -33,7 +31,7 @@ const manifestPlugin = (options) => {
|
|
|
33
31
|
});
|
|
34
32
|
}
|
|
35
33
|
catch (e) {
|
|
36
|
-
|
|
34
|
+
logger.warn(`\nUnable to write manifest file in ${output}, ${e}`);
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
37
|
};
|
package/dist/lib/server.js
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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}`);
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PLATFORM_VERSION } from './constants';
|
|
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;
|
|
@@ -26,7 +28,12 @@ export interface ExtensionConfigMap {
|
|
|
26
28
|
interface CardConfig {
|
|
27
29
|
file: string;
|
|
28
30
|
}
|
|
29
|
-
export interface
|
|
31
|
+
export interface ProjectConfig {
|
|
32
|
+
name: string;
|
|
33
|
+
srcDir: string;
|
|
34
|
+
platformVersion?: PlatformVersion;
|
|
35
|
+
}
|
|
36
|
+
export interface PrivateAppConfig {
|
|
30
37
|
name: string;
|
|
31
38
|
description: string;
|
|
32
39
|
scopes: string[];
|
|
@@ -38,7 +45,38 @@ export interface AppConfig {
|
|
|
38
45
|
};
|
|
39
46
|
uid?: string;
|
|
40
47
|
}
|
|
48
|
+
export interface LocalAppConfig {
|
|
49
|
+
proxy: LocalDevUrlMapping;
|
|
50
|
+
}
|
|
51
|
+
export interface PublicAppConfig {
|
|
52
|
+
name: string;
|
|
53
|
+
uid: string;
|
|
54
|
+
logo?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
allowedUrls?: string[];
|
|
57
|
+
auth?: {
|
|
58
|
+
preventAdditionalScopes: boolean;
|
|
59
|
+
preventOptionalScopes: boolean;
|
|
60
|
+
redirectUrls: string[];
|
|
61
|
+
requiredScopes: string[];
|
|
62
|
+
optionalScopes: string[];
|
|
63
|
+
additionalScopes: string[];
|
|
64
|
+
};
|
|
65
|
+
support?: {
|
|
66
|
+
supportUrl: string;
|
|
67
|
+
supportEmail: string;
|
|
68
|
+
documentationUrl: string;
|
|
69
|
+
supportPhone: string;
|
|
70
|
+
};
|
|
71
|
+
extensions: {
|
|
72
|
+
crm: {
|
|
73
|
+
cards: CardConfig[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export type AppConfig = PrivateAppConfig | PublicAppConfig;
|
|
41
78
|
export interface ProjectComponent {
|
|
79
|
+
type: typeof PUBLIC_APP | typeof PRIVATE_APP;
|
|
42
80
|
config: AppConfig;
|
|
43
81
|
path: string;
|
|
44
82
|
}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.8.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
"prepare": "npm run build",
|
|
11
11
|
"lint": "echo 'no lint step for @hubspot/ui-extensions-dev-server'",
|
|
12
12
|
"jest": "jest --watch",
|
|
13
|
-
"integration-test": "npm run
|
|
13
|
+
"integration-test-private-app": "npm run integration-test-private-app --prefix ./integrationTests/fixtures",
|
|
14
|
+
"integration-test-public-app": "npm run integration-test-public-app --prefix ./integrationTests/fixtures",
|
|
15
|
+
"integration-test": "npm run build && npm run integration-test-private-app && npm run integration-test-public-app"
|
|
14
16
|
},
|
|
15
17
|
"publishConfig": {
|
|
16
18
|
"access": "public"
|
|
17
19
|
},
|
|
18
20
|
"exports": {
|
|
19
|
-
".": "./dist/index.js"
|
|
20
|
-
"./self": "./dist/lib/self.js"
|
|
21
|
+
".": "./dist/index.js"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
@@ -25,11 +26,7 @@
|
|
|
25
26
|
],
|
|
26
27
|
"license": "MIT",
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@hubspot/app-functions-dev-server": "^0.8.
|
|
29
|
-
"@hubspot/cli-lib": "^4.1.6",
|
|
30
|
-
"command-line-args": "^5.2.1",
|
|
31
|
-
"command-line-usage": "^7.0.1",
|
|
32
|
-
"console-log-colors": "^0.4.0",
|
|
29
|
+
"@hubspot/app-functions-dev-server": "^0.8.14",
|
|
33
30
|
"cors": "^2.8.5",
|
|
34
31
|
"detect-port": "1.5.1",
|
|
35
32
|
"estraverse": "^5.3.0",
|
|
@@ -67,5 +64,5 @@
|
|
|
67
64
|
"optional": true
|
|
68
65
|
}
|
|
69
66
|
},
|
|
70
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "1850d1e7967463bfec84fddaa9d5b167a76b55a7"
|
|
71
68
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Rollup } from 'vite';
|
|
2
|
-
export interface CodeInjectionPluginOptions {
|
|
3
|
-
file: string;
|
|
4
|
-
root?: string;
|
|
5
|
-
}
|
|
6
|
-
export type CodeInjectionPlugin = (options: CodeInjectionPluginOptions) => Rollup.Plugin;
|
|
7
|
-
declare const codeInjectionPlugin: CodeInjectionPlugin;
|
|
8
|
-
export default codeInjectionPlugin;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const codeInjectionPlugin = (options) => {
|
|
8
|
-
const { file, root = process.cwd() } = options;
|
|
9
|
-
return {
|
|
10
|
-
name: 'ui-extensions-code-injection-plugin',
|
|
11
|
-
enforce: 'post',
|
|
12
|
-
transform(code, fileBeingTransformed) {
|
|
13
|
-
const absoluteFilePath = path_1.default.isAbsolute(file)
|
|
14
|
-
? file
|
|
15
|
-
: path_1.default.join(root, file);
|
|
16
|
-
if (fileBeingTransformed !== absoluteFilePath) {
|
|
17
|
-
return { code, map: null }; // Not the file we care about, return the same code
|
|
18
|
-
}
|
|
19
|
-
// Update the code to import the self script which houses our overrides
|
|
20
|
-
// This needs to be the first line in the source file so that the overrides get hoisted
|
|
21
|
-
// to the top of the generated source file
|
|
22
|
-
const updatedCode = `import "@hubspot/ui-extensions-dev-server/self"; ${code}`;
|
|
23
|
-
// Return the updated source code. We don't need to include the new code in the
|
|
24
|
-
// sourcemap because we don't want it to show up in the users code when they
|
|
25
|
-
// view the source mapped code in the browser
|
|
26
|
-
return { code: updatedCode, map: null };
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
exports.default = codeInjectionPlugin;
|
package/dist/lib/self.d.ts
DELETED
|
File without changes
|
package/dist/lib/self.js
DELETED