@metricinsights/pp-dev 0.2.0 → 0.3.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.
Files changed (85) hide show
  1. package/README.md +79 -35
  2. package/bin/pp-dev.js +4 -10
  3. package/dist/cjs/cli.js +590 -0
  4. package/dist/cjs/cli.js.map +1 -0
  5. package/dist/cjs/helpers.js +29 -0
  6. package/dist/cjs/helpers.js.map +1 -0
  7. package/dist/cjs/index-24d6a380.js +292 -0
  8. package/dist/cjs/index-24d6a380.js.map +1 -0
  9. package/dist/cjs/index.js +28 -0
  10. package/dist/cjs/index.js.map +1 -0
  11. package/dist/cjs/package.json +113 -0
  12. package/dist/cjs/plugin-24dd0a43.js +878 -0
  13. package/dist/cjs/plugin-24dd0a43.js.map +1 -0
  14. package/dist/cjs/plugin.js +20 -0
  15. package/dist/cjs/plugin.js.map +1 -0
  16. package/dist/esm/cli.js +566 -0
  17. package/dist/esm/cli.js.map +1 -0
  18. package/dist/esm/helpers.js +25 -0
  19. package/dist/esm/helpers.js.map +1 -0
  20. package/dist/esm/index-833c47d2.js +268 -0
  21. package/dist/esm/index-833c47d2.js.map +1 -0
  22. package/dist/esm/index.js +20 -0
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/esm/package.json +113 -0
  25. package/dist/esm/plugin-ecb1c54a.js +843 -0
  26. package/dist/esm/plugin-ecb1c54a.js.map +1 -0
  27. package/dist/esm/plugin.js +14 -0
  28. package/dist/esm/plugin.js.map +1 -0
  29. package/dist/types/cli.d.ts +3 -0
  30. package/dist/types/helpers.d.ts +24 -0
  31. package/dist/types/index.d.ts +18 -0
  32. package/dist/{plugin.d.ts → types/plugin.d.ts} +6 -2
  33. package/package.json +29 -10
  34. package/pp-dev.d.ts +1 -1
  35. package/dist/api/assets.d.ts +0 -15
  36. package/dist/api/assets.js +0 -58
  37. package/dist/api/assets.js.map +0 -1
  38. package/dist/api/constants.d.ts +0 -1
  39. package/dist/api/constants.js +0 -2
  40. package/dist/api/constants.js.map +0 -1
  41. package/dist/api/index.d.ts +0 -2
  42. package/dist/api/index.js +0 -3
  43. package/dist/api/index.js.map +0 -1
  44. package/dist/api/page.d.ts +0 -18
  45. package/dist/api/page.js +0 -46
  46. package/dist/api/page.js.map +0 -1
  47. package/dist/banner/header.d.ts +0 -2
  48. package/dist/banner/header.js +0 -10
  49. package/dist/banner/header.js.map +0 -1
  50. package/dist/cli.d.ts +0 -1
  51. package/dist/cli.js +0 -275
  52. package/dist/cli.js.map +0 -1
  53. package/dist/client/rollup.config.d.ts +0 -2
  54. package/dist/constants.d.ts +0 -6
  55. package/dist/constants.js +0 -18
  56. package/dist/constants.js.map +0 -1
  57. package/dist/index.d.ts +0 -9
  58. package/dist/index.js +0 -150
  59. package/dist/index.js.map +0 -1
  60. package/dist/lib/client.service.d.ts +0 -16
  61. package/dist/lib/client.service.js +0 -59
  62. package/dist/lib/client.service.js.map +0 -1
  63. package/dist/lib/dist.service.d.ts +0 -31
  64. package/dist/lib/dist.service.js +0 -148
  65. package/dist/lib/dist.service.js.map +0 -1
  66. package/dist/lib/helpers/url.helper.d.ts +0 -3
  67. package/dist/lib/helpers/url.helper.js +0 -27
  68. package/dist/lib/helpers/url.helper.js.map +0 -1
  69. package/dist/lib/pp.middleware.d.ts +0 -27
  70. package/dist/lib/pp.middleware.js +0 -155
  71. package/dist/lib/pp.middleware.js.map +0 -1
  72. package/dist/lib/proxy-cache.middleware.d.ts +0 -17
  73. package/dist/lib/proxy-cache.middleware.js +0 -51
  74. package/dist/lib/proxy-cache.middleware.js.map +0 -1
  75. package/dist/lib/proxy-pass.middleware.d.ts +0 -10
  76. package/dist/lib/proxy-pass.middleware.js +0 -90
  77. package/dist/lib/proxy-pass.middleware.js.map +0 -1
  78. package/dist/plugin.js +0 -118
  79. package/dist/plugin.js.map +0 -1
  80. package/dist/plugins/client-injection-plugin.d.ts +0 -12
  81. package/dist/plugins/client-injection-plugin.js +0 -57
  82. package/dist/plugins/client-injection-plugin.js.map +0 -1
  83. package/dist/shortcuts.d.ts +0 -12
  84. package/dist/shortcuts.js +0 -93
  85. package/dist/shortcuts.js.map +0 -1
package/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # pp-dev
2
2
 
3
- Portal Page development framework and build tool.
3
+ The PP Dev Helper is a development framework and build tool for Metric Insights' Portal Pages, designed to make the lives of PP developers easier:
4
+ - build your Portal Page
5
+ - run/test locally with API requests proxied to a Metric Insights server
6
+ - a lot more (to be documented soon!)
4
7
 
5
- This package is based on [Vite](https://vitejs.dev/) tool.
8
+ pp-dev is based on [Vite](https://vitejs.dev/).
6
9
 
7
10
  ## Usage
8
11
 
@@ -12,13 +15,14 @@ Package installation
12
15
  $ npm i @metricinsights/pp-dev
13
16
  ```
14
17
 
15
- ### Define configuration
18
+ ### Define Configuration
16
19
 
17
- You need to create the file with the name `pp-dev.config` and extension `js` or
18
- `cjs` (if you define type `module` in package.json) or `ts` if you want to use Typescript, or `json`.
19
- You also can define configuration in `package.json` with the `pp-dev` key
20
+ You'll need to create a file with the name `pp-dev.config` and extension `js` or
21
+ `cjs` (if you define type `module` in package.json), or `ts` if you want to use TypeScript, or `json`.
20
22
 
21
- Config examples:
23
+ Alternatively, you can define configuration in your `package.json` via the `pp-dev` key
24
+
25
+ Generic configuration examples:
22
26
 
23
27
  - JavaScript
24
28
 
@@ -26,15 +30,15 @@ Config examples:
26
30
  // pp-dev.config.js
27
31
 
28
32
  /**
29
- * @type {import('@metricinsights/pp-dev').PPDevConfig}
30
- */
33
+ * @type {import('@metricinsights/pp-dev').PPDevConfig}
34
+ */
31
35
  module.exports = {
32
- backendBaseURL: 'https://example.metricinsights.com',
33
- portalPageId: 1,
36
+ backendBaseURL: 'https://mi.company.com',
37
+ portalPageId: 1,
34
38
  };
35
39
  ```
36
40
 
37
- - Typescript
41
+ - TypeScript
38
42
 
39
43
  ```typescript
40
44
  // pp-dev.config.ts
@@ -42,40 +46,62 @@ portalPageId: 1,
42
46
  import { PPDevConfig } from '@metricinsights/pp-dev';
43
47
 
44
48
  const config: PPDevConfig = {
45
- backendBaseURL: 'https://example.metricinsights.com',
46
- portalPageId: 1,
49
+ backendBaseURL: 'https://mi.company.com',
50
+ portalPageId: 1,
47
51
  };
48
52
 
49
53
  export default config;
50
54
  ```
51
55
 
52
- - JSON (`pp-dev.config.json`)
56
+ - JSON as `pp-dev.config.json`
53
57
 
54
58
  ```json
55
59
  {
56
- "backendBaseURL": "https://example.metricinsights.com",
57
- "portalPageId": 1
60
+ "backendBaseURL": "https://mi.company.com",
61
+ "portalPageId": 1
58
62
  }
59
63
  ```
60
64
 
61
- - JSON in `package.json` file
65
+ - JSON as `package.json`
62
66
 
63
67
  ```json
64
68
  {
65
- "name": "<project-name>",
66
- "version": "1.0.0",
67
- "scripts": {},
68
- "pp-dev": {
69
- "backendBaseURL": "https://example.metricinsights.com",
70
- "portalPageId": 1
71
- }
69
+ "name": "<project-name>",
70
+ "version": "1.0.0",
71
+ "scripts": {},
72
+ "pp-dev": {
73
+ "backendBaseURL": "https://mi.company.com",
74
+ "portalPageId": 1
75
+ }
72
76
  }
73
77
  ```
74
78
 
79
+ ## [Next.js](https://nextjs.org/) Configuration
80
+
81
+ To use the PP Dev Helper with Next.js:
82
+
83
+ 1. Add pp-dev config to your root directory.
84
+
85
+ 2. Change your `dev` script in `package.json` to `pp-dev next`.
86
+
87
+ 3. Finally, wrap your next.config with a `withPPDev` function.
88
+
89
+ ```javascript
90
+ // next.config.js
91
+
92
+ const { withPPDev } = require('@metricinsights/pp-dev');
93
+
94
+ module.exports = withPPDev({
95
+ // your next config
96
+ });
97
+ ```
98
+
99
+
100
+
75
101
  ### Vite configuration
76
102
 
77
- If you need to change something in the build you can define `vite.config` file.
78
- More description you can find [here](https://vitejs.dev/config/)
103
+ If you need to change something in the build you can define a `vite.config` file.
104
+ More details [Vite Confighere](https://vitejs.dev/config/)
79
105
 
80
106
  ### Configuration API description
81
107
 
@@ -83,7 +109,7 @@ More description you can find [here](https://vitejs.dev/config/)
83
109
 
84
110
  Type: String
85
111
 
86
- Example: `https://example.metricinsights.com`
112
+ Example: `https://mi.company.com`
87
113
 
88
114
  Description: Defines the backend URL (Metric Insights instance) that is used for proxying requests to the MI backend
89
115
 
@@ -93,7 +119,7 @@ Type: Number
93
119
 
94
120
  Example: `1`
95
121
 
96
- Description: Defines the Portal Page Id that used to get portal page variables values.
122
+ Description: Defines the Portal Page ID that used to get Portal Page Variable values.
97
123
 
98
124
  #### `miHudLess`
99
125
 
@@ -113,7 +139,23 @@ Default: `false`
113
139
 
114
140
  Example: `true`
115
141
 
116
- Description: Disables template variables transforming. Used when you develop the portal page without a template
142
+ Description: Disables Template Variables transformation. Used when developing a Portal Page without a template
143
+
144
+ #### `enableProxyCache`
145
+
146
+ Type: Boolean
147
+
148
+ Default: `true`
149
+
150
+ Description: Enables proxy cache. If you want to disable proxy cache, you need to set this option to `false`
151
+
152
+ #### `proxyCacheTTL`
153
+
154
+ Type: Number
155
+
156
+ Default: `10 * 60 * 1000`
157
+
158
+ Description: Defines proxy cache TTL in milliseconds
117
159
 
118
160
  ### CLI API description
119
161
 
@@ -122,9 +164,10 @@ Description: Disables template variables transforming. Used when you develop the
122
164
  - `pp-dev` or `pp-dev serve` or `pp-dev dev` runs application in development mode
123
165
  - `pp-dev build` starts the application build. Will create `dist` and `dist-zip` folders. `dist` folder contains unzipped build files. `dist-zip` contains file `<package-name>.zip` with files from the `dist` folder
124
166
 
125
- ## Migration guide from old portal page helper to new
126
167
 
127
- 1. You need to initialize npm in your portal page repository (if you have `package.json` file in PP folder, you can skip this step):
168
+ ## Migration guide from old Portal Page Helper to new
169
+
170
+ 1. Initialize npm in your portal page repository (if you have `package.json` file in PP folder, you can skip this step):
128
171
 
129
172
  Go to portal page folder and run command. This command will create `package.json` file in your folder
130
173
 
@@ -132,17 +175,18 @@ Description: Disables template variables transforming. Used when you develop the
132
175
  $ npm init
133
176
  ```
134
177
 
135
- 2. You need to install this package by this command:
178
+ 2. Install this package by this command:
136
179
  ```shell
137
180
  $ npm i @metricinsights/pp-dev
138
181
  ```
139
- 3. You need to create two scripts in `package.json` script section.
182
+ 3. Create two scripts in `package.json` script section.
140
183
 
141
184
  - `start` script: `"start": "pp-dev"`
142
185
  - `build` script: `"build": "pp-dev build"`
143
186
 
144
- 4. You need to change all paths to the file in index.html to the absolute path.
187
+ 4. Change all paths to the file in index.html to the absolute path.
145
188
  If you have a path like `/pt/main.js` this must be changed to `/main.js`.
146
189
  Also, you may need to add `type="module"` to every script that is added by the `script` tag with the `src` property.
147
190
  Actually would be good to have only one `script` tag with the `src` tag.
148
191
  Every other JS file will be imported with construction like this `import helper from './helpers';`
192
+
package/bin/pp-dev.js CHANGED
@@ -13,12 +13,8 @@ if (!import.meta.url.includes('node_modules')) {
13
13
  global.__pp_dev_start_time = performance.now();
14
14
 
15
15
  // check debug mode first before requiring the CLI.
16
- const debugIndex = process.argv.findIndex((arg) =>
17
- /^(?:-d|--debug)$/.test(arg),
18
- );
19
- const filterIndex = process.argv.findIndex((arg) =>
20
- /^(?:-f|--filter)$/.test(arg),
21
- );
16
+ const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg));
17
+ const filterIndex = process.argv.findIndex((arg) => /^(?:-f|--filter)$/.test(arg));
22
18
  const profileIndex = process.argv.indexOf('--profile');
23
19
 
24
20
  if (debugIndex > 0) {
@@ -33,9 +29,7 @@ if (debugIndex > 0) {
33
29
  .map((v) => `pp-dev:${v},vite:${v}`)
34
30
  .join(',');
35
31
  }
36
- process.env.DEBUG = `${
37
- process.env.DEBUG ? process.env.DEBUG + ',' : ''
38
- }${value}`;
32
+ process.env.DEBUG = `${process.env.DEBUG ? process.env.DEBUG + ',' : ''}${value}`;
39
33
 
40
34
  if (filterIndex > 0) {
41
35
  const filter = process.argv[filterIndex + 1];
@@ -48,7 +42,7 @@ if (debugIndex > 0) {
48
42
  }
49
43
 
50
44
  function start() {
51
- return import('../dist/cli.js');
45
+ return import('../dist/esm/cli.js');
52
46
  }
53
47
 
54
48
  if (profileIndex > 0) {