@pendo/agent 2.281.0 → 2.282.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/README.md CHANGED
@@ -95,21 +95,24 @@ The current list of available plugins and their export names are:
95
95
 
96
96
  Writing an extension that adheres to the strict requirements of Manifest V3 can sometimes be challenging. If you have a Manifest V3 extension that you would like to install Pendo into, in order to understand how your customers use your extension, you will need to follow a few steps to ensure that the Pendo agent does not fetch any remote code. Using this npm package is the most straightforward way to include all Pendo assets in your extension.
97
97
 
98
- 1. Use the [CLI](#cli) to copy the agent static files into a folder that will be included in your packaged extension (ensure this is run each time you update your agent version).
98
+ 1. Use the [CLI](#cli) to copy the agent static files, using the `copy` command, into a folder that will be included in your packaged extension (ensure this is run each time you update your agent version).
99
+ 1. Use the [CLI](#cli) to download copies of the designer plugin files, using the `designer` command, into your packaged extension (ensure this runs each time you rebuild your extension to ensure you have the latest designer code).
99
100
  1. Update the `manifest.json` file to include those copied files in your "web_accessible_resources". The files copied are: "guide.css", "pendo.debugger.min.js", "debugger-plugin.min.js", "pendo.preview.min.js", "replay.worker.min.js" (the worker is only needed if using Pendo Session Replay)
100
101
  1. Initialize Pendo on the desired page or pages with any desired options, making sure to use the [assets option](#assets).
101
- 1. The "host" field will need to be the extension resource url. It will probably look like this: `chrome.runtime.getURL('').slice(0, -1)`
102
+ 1. The "host" field will need to be the extension resource url. You can use a code snippet like this to properly retrieve that url: `chrome.runtime.getURL('').slice(0, -1)`
102
103
  1. The "path" field will need to be set to whatever the folder the assets were copied to. If they are in the root of your packaged extension this can be an empty string but if, for example, those assets are in a folder called `pendo`, the "path" would just be `pendo`.
103
- 1. The "localOnly" field will need to be set `true` in your final packaged extension. This does mean that you will not be able to launch the designer in the store version of your extension however. In order to utilize Visual Design Studio you will need to use a dev unpackaged version of your extension where "localOnly" is either not set or set to `false`.
104
+ 1. The "localOnly" field will need to be set `true` in order to disable remote code execution and allow the designer to launch using your extension's files.
105
+
106
+ We have created an [example extension](https://github.com/pendo-io/chrome-mv3-example) to show what a basic setup might look like.
104
107
 
105
108
  ## CLI
106
109
 
107
110
  The Pendo package includes a CLI tool to be able to simplify a few actions providing greater control of the Pendo Agent in your application. Once you have installed `@pendo/agent` in your application, you will have access to the `pendo` script from your terminal (you can also use a tool like `npx` to make use of the `pendo` script without installing the package if desired by using `npx pendo`). The usage of this script can be found below or by typing `pendo` or `pendo help` into your terminal where the package is installed:
108
111
 
109
- > **Note**: If the config and copy commands are being used by your application, you might want to use those as part of your regular build process to ensure that you always maintain up to date versions of your config and of the static assets. For example, you could add a script to your package.json like below that you then call as part of your build:
112
+ > **Note**: If the config, copy, or designer commands are being used by your application, you might want to use those as part of your regular build process to ensure that you always maintain up to date versions of your config and of the static assets. For example, you could add a script to your package.json like below that you then call as part of your build:
110
113
 
111
114
  ```json
112
- "pendo-build": "pendo copy --dest=public && pendo config --apiKey={{APIKEY}} --env={{YOUR_ENV}}",
115
+ "pendo-build": "pendo copy --dest=public && pendo config --apiKey={{APIKEY}} --env={{YOUR_ENV}} && pendo designer --dest=public --env={{YOUR_ENV}}",
113
116
  ```
114
117
 
115
118
  ### Help
@@ -162,3 +165,19 @@ Examples:
162
165
  Copy from the default location to your public folder
163
166
  $ pendo copy --dest=public
164
167
  ```
168
+
169
+ ### Download Designer Plugins
170
+
171
+ ```bash
172
+ Usage: pendo designer --env=<subscription_environment> --dest=<destination_folder>
173
+
174
+ Download new copies of the plugin files needed for the Visual Design Studio to launch and operate correctly.
175
+
176
+ Options:
177
+ --env required, the Pendo environment for your subscription, allowed environments: [${environments}]
178
+ --dest required, the destination folder to copy the static files to, usually the "public" folder of your application
179
+
180
+ Examples:
181
+ Download and save the designer files from the default US environment
182
+ $ pendo designer --env=io --dest=public`
183
+ ```
package/bin/cli.js CHANGED
@@ -4,6 +4,7 @@ import minimist from 'minimist';
4
4
  import https from 'https';
5
5
  import fs from 'fs';
6
6
  import path from 'path';
7
+ import zlib from 'zlib';
7
8
 
8
9
  const options = minimist(process.argv.slice(2));
9
10
 
@@ -24,7 +25,6 @@ function config() {
24
25
  options.output = 'pendo.config.json';
25
26
  }
26
27
 
27
- const file = fs.createWriteStream(options.output);
28
28
  const url = new URL(`agent/static/${options.apiKey}/config.json`, `https://${servers.assetHost[options.env]}`).toString();
29
29
  try {
30
30
  https.get(url, function(response) {
@@ -38,17 +38,12 @@ function config() {
38
38
  delete config.stagingAgentUrl;
39
39
  delete config.stagingServerHashes;
40
40
  delete config.stagingServers;
41
- });
42
-
43
- response.pipe(file);
44
-
45
- file.on('finish', () => {
46
- file.close();
41
+ fs.writeFileSync(options.output, JSON.stringify(config, null, 4), 'utf8');
47
42
  console.debug('Pendo Agent config downloaded successfully');
48
43
  });
49
44
  });
50
45
  } catch (err) {
51
- console.error(`Unable to download new Pendo Agent config file, please confirm the apiKey and contentHost. apiKey=${options.apiKey}, contentHost=${options.contentHost}`);
46
+ console.error(`Unable to download new Pendo Agent config file, please confirm the apiKey and contentHost. apiKey=${options.apiKey}, contentHost=${options.contentHost}`, err);
52
47
  }
53
48
  }
54
49
 
@@ -109,6 +104,77 @@ Examples:
109
104
  $ pendo copy --dest=public`);
110
105
  }
111
106
 
107
+ function designer() {
108
+ const servers = JSON.parse(fs.readFileSync(new URL('../dist/servers.json', import.meta.url), 'utf8'));
109
+ if (!options.env || !servers.ENV[options.env]) {
110
+ console.error('Missing or invalid option "env", please provide a valid environment for your subscription using the "--env=" parameter');
111
+ console.error('\nExample: $ pendo designer --env=io');
112
+ process.exit(1);
113
+ }
114
+ if (!options.dest || typeof options.dest !== 'string') {
115
+ console.error('Missing required option "dest" to save designer plugin files to, please provide the destination folder for your project using the "--dest=" parameter.');
116
+ console.error('\nExample: $ pendo designer --dest=public');
117
+ process.exit(1);
118
+ }
119
+
120
+ const designerFiles = ['plugin.js', 'preloader.js'];
121
+
122
+ designerFiles.forEach(filename => {
123
+ try {
124
+ const pluginUrl = new URL(`in-app-designer/latest/${filename}`, `${servers.data[options.env]}`).toString();
125
+ const filePath = path.join(options.dest, filename);
126
+ const file = fs.createWriteStream(filePath);
127
+
128
+ const requestOptions = {
129
+ headers: {
130
+ 'Accept-Encoding': 'gzip'
131
+ }
132
+ };
133
+
134
+ https.get(pluginUrl, requestOptions, function(response) {
135
+ let error;
136
+
137
+ if (response.headers['content-encoding'] === 'gzip') {
138
+ response = response.pipe(zlib.createGunzip());
139
+ }
140
+
141
+ response.pipe(file);
142
+
143
+ response.on('error', () => {
144
+ error = true;
145
+ file.close();
146
+ });
147
+
148
+ file.on('finish', () => {
149
+ file.close();
150
+ if (error) {
151
+ console.debug(`Error downloading Pendo Visual Design Studio ${filename}, please confirm the environment and destination. env=${options.env}, dest=${options.dest}`);
152
+ } else {
153
+ console.debug(`Pendo Visual Design Studio ${filename} downloaded successfully`);
154
+ }
155
+ });
156
+ });
157
+ } catch (err) {
158
+ console.error(`Unable to download new Pendo designer plugin file ${filename}, please confirm the environment and destination. env=${options.env}, dest=${options.dest}`, err);
159
+ }
160
+ });
161
+ }
162
+
163
+ function designerHelp() {
164
+ const environments = Object.keys(JSON.parse(fs.readFileSync(new URL('../dist/servers.json', import.meta.url), 'utf8')).ENV);
165
+ console.log(`Usage: pendo designer --env=<subscription_environment> --dest=<destination_folder>
166
+
167
+ Download new copies of the plugin files needed for the Visual Design Studio to launch and operate correctly.
168
+
169
+ Options:
170
+ --env required, the Pendo environment for your subscription, allowed environments: [${environments}]
171
+ --dest required, the destination folder to copy the static files to, usually the "public" folder of your application
172
+
173
+ Examples:
174
+ Download and save the designer files from the default US environment
175
+ $ pendo designer --env=io --dest=public`);
176
+ }
177
+
112
178
  function version() {
113
179
  const packageFile = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
114
180
  console.log(packageFile.version);
@@ -121,9 +187,10 @@ Show the current version of the Pendo Agent installed.`);
121
187
  }
122
188
 
123
189
  const helpers = {
124
- 'config': configHelp,
125
- 'copy': copyHelp,
126
- 'version': versionHelp
190
+ config: configHelp,
191
+ copy: copyHelp,
192
+ designer: designerHelp,
193
+ version: versionHelp
127
194
  };
128
195
 
129
196
  function help() {
@@ -137,6 +204,7 @@ CLI for @pendo/agent to assist in integrating the Pendo Agent into your applicat
137
204
  Commands:
138
205
  pendo config download a new Pendo Agent configuration file for your application
139
206
  pendo copy copy static assets for the Pendo Agent to a static folder
207
+ pendo designer download new copies of the plugin files needed for the Visual Design Studio
140
208
  pendo help provide help for how to use the Pendo CLI
141
209
  pendo help <command> search for help on a specific <command>
142
210
  pendo version show the current version of the Pendo Agent
@@ -157,6 +225,7 @@ Documentation for the Pendo Agent can be found at:
157
225
  const commands = {
158
226
  config,
159
227
  copy,
228
+ designer,
160
229
  help,
161
230
  version
162
231
  };