@tywalk/pcf-helper 1.5.5 → 1.5.6

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.
@@ -52,7 +52,7 @@ program
52
52
  .option('-t, --stylesheet <stylesheet>', 'remote stylesheet to intercept')
53
53
  .option('-b, --bundle <path>', 'local bundle path')
54
54
  .option('-c, --css <path>', 'local CSS path')
55
- .option('-f, --config <path>', 'config file path', 'dev-config.json')
55
+ .option('-f, --config <path>', 'config file path', 'session.config.json')
56
56
  .parse();
57
57
  const options = program.opts();
58
58
  if (options.verbose) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Command line helper for building and publishing PCF controls to Dataverse.",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/",
@@ -15,7 +15,8 @@
15
15
  "test": "jest",
16
16
  "build": "tsc",
17
17
  "upgrade": "npm version patch --no-git-tag-version",
18
- "ready": "npm run upgrade && npm run build && npm publish --access public"
18
+ "ready": "npm run upgrade && npm run build",
19
+ "update": "npm run ready && npm publish --access public"
19
20
  },
20
21
  "keywords": [
21
22
  "pcf"
@@ -18,10 +18,18 @@ const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
18
18
  const path_1 = __importDefault(require("path"));
19
19
  const fs_1 = __importDefault(require("fs"));
20
20
  const playwright_1 = require("playwright");
21
+ /**
22
+ * Loads configuration for the session task, supporting a combination of config file, environment variables, and CLI arguments.
23
+ * The priority order is: CLI arguments > environment variables > config file > defaults.
24
+ * It also handles constructing full URLs for the script and stylesheet to intercept, allowing for relative paths in the config that are combined with the base URL.
25
+ * @param config Optional path to a JSON config file. If not provided, it will look for 'session.config.json' in the current working directory.
26
+ * @returns An object containing the resolved configuration values for the session task.
27
+ */
21
28
  function loadConfig(config) {
29
+ var _a, _b;
22
30
  // Load file config if exists
23
31
  let fileConfig = {};
24
- const configPath = path_1.default.join(process.cwd(), config || 'dev-config.json');
32
+ const configPath = path_1.default.join(process.cwd(), config || 'session.config.json');
25
33
  color_logger_1.default.log(`📁 Looking for config file at: ${configPath}`);
26
34
  if (fs_1.default.existsSync(configPath)) {
27
35
  fileConfig = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
@@ -35,12 +43,10 @@ function loadConfig(config) {
35
43
  }
36
44
  // Get the base URL first
37
45
  const remoteEnvironmentUrl = process.env.REMOTE_ENVIRONMENT_URL ||
38
- fileConfig.remoteEnvironmentUrl ||
39
- 'https://app.your-remote-environment.com';
46
+ fileConfig.remoteEnvironmentUrl;
40
47
  // Handle script argument - support both relative paths and full URLs
41
48
  let remoteScriptToIntercept = process.env.REMOTE_SCRIPT_TO_INTERCEPT ||
42
- fileConfig.remoteScriptToIntercept ||
43
- 'https://app.your-remote-environment.com/static/js/remote-control-bundle.js';
49
+ fileConfig.remoteScriptToIntercept;
44
50
  // If script is a relative path (doesn't start with http/https), combine with base URL
45
51
  if (remoteScriptToIntercept && !remoteScriptToIntercept.startsWith('http')) {
46
52
  // Normalize the base URL (remove trailing slash)
@@ -52,8 +58,7 @@ function loadConfig(config) {
52
58
  remoteScriptToIntercept = `${baseUrl}${scriptPath}`;
53
59
  }
54
60
  let remoteStylesheetToIntercept = process.env.REMOTE_STYLESHEET_TO_INTERCEPT ||
55
- fileConfig.remoteStylesheetToIntercept ||
56
- 'https://app.your-remote-environment.com/static/css/remote-control-styles.css';
61
+ fileConfig.remoteStylesheetToIntercept;
57
62
  // If stylesheet is a relative path (doesn't start with http/https), combine with base URL
58
63
  if (remoteStylesheetToIntercept && !remoteStylesheetToIntercept.startsWith('http')) {
59
64
  // Normalize the base URL (remove trailing slash)
@@ -69,19 +74,41 @@ function loadConfig(config) {
69
74
  remoteEnvironmentUrl: remoteEnvironmentUrl,
70
75
  remoteScriptToIntercept: remoteScriptToIntercept,
71
76
  remoteStylesheetToIntercept: remoteStylesheetToIntercept,
72
- localCssPath: process.env.LOCAL_CSS_PATH ||
73
- fileConfig.localCssPath ||
74
- path_1.default.join(process.cwd(), 'dist', 'local-control-styles.css'),
75
- localBundlePath: process.env.LOCAL_BUNDLE_PATH ||
76
- fileConfig.localBundlePath ||
77
- path_1.default.join(process.cwd(), 'dist', 'local-control-bundle.js')
77
+ localCssPath: (_a = process.env.LOCAL_CSS_PATH) !== null && _a !== void 0 ? _a : fileConfig.localCssPath,
78
+ localBundlePath: (_b = process.env.LOCAL_BUNDLE_PATH) !== null && _b !== void 0 ? _b : fileConfig.localBundlePath,
78
79
  };
79
80
  }
81
+ /**
82
+ * Runs an ephemeral browser session that intercepts requests to the specified remote script and stylesheet URLs, serving local files instead.
83
+ * It also manages session state by saving cookies and local storage to a file, allowing for persistent login sessions across runs.
84
+ * The session will automatically clean up and save state on exit, including handling various exit signals and browser events.
85
+ * @param remoteEnvironmentUrl The URL of the remote environment to navigate to.
86
+ * @param remoteScriptToIntercept The full URL of the remote script to intercept (e.g., https://app.your-remote-environment.com/static/js/remote-control-bundle.js).
87
+ * @param remoteStylesheetToIntercept The full URL of the remote stylesheet to intercept (e.g., https://app.your-remote-environment.com/static/css/remote-control-styles.css).
88
+ * @param localBundlePath The local file path to the JavaScript bundle that should be served when the remote script URL is requested.
89
+ * @param localCssPath The local file path to the CSS file that should be served when the remote stylesheet URL is requested.
90
+ */
80
91
  function runSession(remoteEnvironmentUrl, remoteScriptToIntercept, remoteStylesheetToIntercept, localBundlePath, localCssPath) {
81
92
  if (!remoteEnvironmentUrl) {
82
93
  color_logger_1.default.error('❌ Remote environment URL is required. Please provide it via CLI, config file, or environment variable.');
83
94
  process.exit(1);
84
95
  }
96
+ if (!remoteScriptToIntercept) {
97
+ color_logger_1.default.error('❌ Remote script URL to intercept is required. Please provide it via CLI, config file, or environment variable.');
98
+ process.exit(1);
99
+ }
100
+ if (!remoteStylesheetToIntercept) {
101
+ color_logger_1.default.error('❌ Remote stylesheet URL to intercept is required. Please provide it via CLI, config file, or environment variable.');
102
+ process.exit(1);
103
+ }
104
+ if (!localBundlePath) {
105
+ color_logger_1.default.error('❌ Local bundle path is required. Please provide it via CLI, config file, or environment variable.');
106
+ process.exit(1);
107
+ }
108
+ if (!localCssPath) {
109
+ color_logger_1.default.error('❌ Local CSS path is required. Please provide it via CLI, config file, or environment variable.');
110
+ process.exit(1);
111
+ }
85
112
  const REMOTE_ENVIRONMENT_URL = remoteEnvironmentUrl;
86
113
  const REMOTE_SCRIPT_TO_INTERCEPT = remoteScriptToIntercept;
87
114
  const REMOTE_STYLESHEET_TO_INTERCEPT = remoteStylesheetToIntercept;
@@ -180,7 +207,7 @@ function runSession(remoteEnvironmentUrl, remoteScriptToIntercept, remoteStylesh
180
207
  return false;
181
208
  }
182
209
  // Match script URLs that end with the same path structure
183
- return route.href.includes(scriptPattern) && route.href.includes('bundle.js');
210
+ return route.href.includes(scriptPattern);
184
211
  }, (route) => __awaiter(this, void 0, void 0, function* () {
185
212
  color_logger_1.default.log(`✅ Intercepted script request: ${route.request().url()}`);
186
213
  color_logger_1.default.log(` Serving local file: ${LOCAL_BUNDLE_PATH}`);
@@ -195,7 +222,7 @@ function runSession(remoteEnvironmentUrl, remoteScriptToIntercept, remoteStylesh
195
222
  return false;
196
223
  }
197
224
  // Match CSS URLs that end with the same path structure
198
- return route.href.includes(stylesheetPattern) && route.href.includes('ItemDescriptionPCF.css');
225
+ return route.href.includes(stylesheetPattern);
199
226
  }, (route) => __awaiter(this, void 0, void 0, function* () {
200
227
  color_logger_1.default.log(`✅ Intercepted CSS request: ${route.request().url()}`);
201
228
  color_logger_1.default.log(` Serving local file: ${LOCAL_CSS_PATH}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Command line helper for building and publishing PCF controls to Dataverse.",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/",
@@ -15,7 +15,8 @@
15
15
  "test": "jest",
16
16
  "build": "tsc",
17
17
  "upgrade": "npm version patch --no-git-tag-version",
18
- "ready": "npm run upgrade && npm run build && npm publish --access public"
18
+ "ready": "npm run upgrade && npm run build",
19
+ "update": "npm run ready && npm publish --access public"
19
20
  },
20
21
  "keywords": [
21
22
  "pcf"
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Loads configuration for the session task, supporting a combination of config file, environment variables, and CLI arguments.
3
+ * The priority order is: CLI arguments > environment variables > config file > defaults.
4
+ * It also handles constructing full URLs for the script and stylesheet to intercept, allowing for relative paths in the config that are combined with the base URL.
5
+ * @param config Optional path to a JSON config file. If not provided, it will look for 'session.config.json' in the current working directory.
6
+ * @returns An object containing the resolved configuration values for the session task.
7
+ */
1
8
  declare function loadConfig(config?: string): {
2
9
  remoteEnvironmentUrl?: undefined;
3
10
  remoteScriptToIntercept?: undefined;
@@ -11,5 +18,15 @@ declare function loadConfig(config?: string): {
11
18
  localCssPath: any;
12
19
  localBundlePath: any;
13
20
  };
21
+ /**
22
+ * Runs an ephemeral browser session that intercepts requests to the specified remote script and stylesheet URLs, serving local files instead.
23
+ * It also manages session state by saving cookies and local storage to a file, allowing for persistent login sessions across runs.
24
+ * The session will automatically clean up and save state on exit, including handling various exit signals and browser events.
25
+ * @param remoteEnvironmentUrl The URL of the remote environment to navigate to.
26
+ * @param remoteScriptToIntercept The full URL of the remote script to intercept (e.g., https://app.your-remote-environment.com/static/js/remote-control-bundle.js).
27
+ * @param remoteStylesheetToIntercept The full URL of the remote stylesheet to intercept (e.g., https://app.your-remote-environment.com/static/css/remote-control-styles.css).
28
+ * @param localBundlePath The local file path to the JavaScript bundle that should be served when the remote script URL is requested.
29
+ * @param localCssPath The local file path to the CSS file that should be served when the remote stylesheet URL is requested.
30
+ */
14
31
  declare function runSession(remoteEnvironmentUrl: string, remoteScriptToIntercept: string, remoteStylesheetToIntercept: string, localBundlePath: string, localCssPath: string): void;
15
32
  export { runSession, loadConfig };