@automattic/jetpack-boost-score-api 0.1.0

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/.gitattributes ADDED
@@ -0,0 +1,16 @@
1
+ # Files not needed to be distributed in the package.
2
+ .gitattributes export-ignore
3
+ node_modules export-ignore
4
+ package.json export-ignore
5
+
6
+ /build/** production-exclude
7
+
8
+ # Files to exclude from the mirror repo
9
+ /changelog/** production-exclude
10
+ /.eslintrc.cjs production-exclude
11
+ .gitignore production-exclude
12
+ tests/** production-exclude
13
+ babel.config.js production-exclude
14
+ webpack.config.js production-exclude
15
+ tsconfig.json production-exclude
16
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## 0.1.0 - 2023-05-29
9
+ ### Added
10
+ - Create package for the boost score bar API [#30781]
package/LICENSE.txt ADDED
@@ -0,0 +1,357 @@
1
+ This program is free software; you can redistribute it and/or modify
2
+ it under the terms of the GNU General Public License as published by
3
+ the Free Software Foundation; either version 2 of the License, or
4
+ (at your option) any later version.
5
+
6
+ This program is distributed in the hope that it will be useful,
7
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
+ GNU General Public License for more details.
10
+
11
+ You should have received a copy of the GNU General Public License
12
+ along with this program; if not, write to the Free Software
13
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
+
15
+
16
+ ===================================
17
+
18
+
19
+ GNU GENERAL PUBLIC LICENSE
20
+ Version 2, June 1991
21
+
22
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
23
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
+ Everyone is permitted to copy and distribute verbatim copies
25
+ of this license document, but changing it is not allowed.
26
+
27
+ Preamble
28
+
29
+ The licenses for most software are designed to take away your
30
+ freedom to share and change it. By contrast, the GNU General Public
31
+ License is intended to guarantee your freedom to share and change free
32
+ software--to make sure the software is free for all its users. This
33
+ General Public License applies to most of the Free Software
34
+ Foundation's software and to any other program whose authors commit to
35
+ using it. (Some other Free Software Foundation software is covered by
36
+ the GNU Lesser General Public License instead.) You can apply it to
37
+ your programs, too.
38
+
39
+ When we speak of free software, we are referring to freedom, not
40
+ price. Our General Public Licenses are designed to make sure that you
41
+ have the freedom to distribute copies of free software (and charge for
42
+ this service if you wish), that you receive source code or can get it
43
+ if you want it, that you can change the software or use pieces of it
44
+ in new free programs; and that you know you can do these things.
45
+
46
+ To protect your rights, we need to make restrictions that forbid
47
+ anyone to deny you these rights or to ask you to surrender the rights.
48
+ These restrictions translate to certain responsibilities for you if you
49
+ distribute copies of the software, or if you modify it.
50
+
51
+ For example, if you distribute copies of such a program, whether
52
+ gratis or for a fee, you must give the recipients all the rights that
53
+ you have. You must make sure that they, too, receive or can get the
54
+ source code. And you must show them these terms so they know their
55
+ rights.
56
+
57
+ We protect your rights with two steps: (1) copyright the software, and
58
+ (2) offer you this license which gives you legal permission to copy,
59
+ distribute and/or modify the software.
60
+
61
+ Also, for each author's protection and ours, we want to make certain
62
+ that everyone understands that there is no warranty for this free
63
+ software. If the software is modified by someone else and passed on, we
64
+ want its recipients to know that what they have is not the original, so
65
+ that any problems introduced by others will not reflect on the original
66
+ authors' reputations.
67
+
68
+ Finally, any free program is threatened constantly by software
69
+ patents. We wish to avoid the danger that redistributors of a free
70
+ program will individually obtain patent licenses, in effect making the
71
+ program proprietary. To prevent this, we have made it clear that any
72
+ patent must be licensed for everyone's free use or not licensed at all.
73
+
74
+ The precise terms and conditions for copying, distribution and
75
+ modification follow.
76
+
77
+ GNU GENERAL PUBLIC LICENSE
78
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
79
+
80
+ 0. This License applies to any program or other work which contains
81
+ a notice placed by the copyright holder saying it may be distributed
82
+ under the terms of this General Public License. The "Program", below,
83
+ refers to any such program or work, and a "work based on the Program"
84
+ means either the Program or any derivative work under copyright law:
85
+ that is to say, a work containing the Program or a portion of it,
86
+ either verbatim or with modifications and/or translated into another
87
+ language. (Hereinafter, translation is included without limitation in
88
+ the term "modification".) Each licensee is addressed as "you".
89
+
90
+ Activities other than copying, distribution and modification are not
91
+ covered by this License; they are outside its scope. The act of
92
+ running the Program is not restricted, and the output from the Program
93
+ is covered only if its contents constitute a work based on the
94
+ Program (independent of having been made by running the Program).
95
+ Whether that is true depends on what the Program does.
96
+
97
+ 1. You may copy and distribute verbatim copies of the Program's
98
+ source code as you receive it, in any medium, provided that you
99
+ conspicuously and appropriately publish on each copy an appropriate
100
+ copyright notice and disclaimer of warranty; keep intact all the
101
+ notices that refer to this License and to the absence of any warranty;
102
+ and give any other recipients of the Program a copy of this License
103
+ along with the Program.
104
+
105
+ You may charge a fee for the physical act of transferring a copy, and
106
+ you may at your option offer warranty protection in exchange for a fee.
107
+
108
+ 2. You may modify your copy or copies of the Program or any portion
109
+ of it, thus forming a work based on the Program, and copy and
110
+ distribute such modifications or work under the terms of Section 1
111
+ above, provided that you also meet all of these conditions:
112
+
113
+ a) You must cause the modified files to carry prominent notices
114
+ stating that you changed the files and the date of any change.
115
+
116
+ b) You must cause any work that you distribute or publish, that in
117
+ whole or in part contains or is derived from the Program or any
118
+ part thereof, to be licensed as a whole at no charge to all third
119
+ parties under the terms of this License.
120
+
121
+ c) If the modified program normally reads commands interactively
122
+ when run, you must cause it, when started running for such
123
+ interactive use in the most ordinary way, to print or display an
124
+ announcement including an appropriate copyright notice and a
125
+ notice that there is no warranty (or else, saying that you provide
126
+ a warranty) and that users may redistribute the program under
127
+ these conditions, and telling the user how to view a copy of this
128
+ License. (Exception: if the Program itself is interactive but
129
+ does not normally print such an announcement, your work based on
130
+ the Program is not required to print an announcement.)
131
+
132
+ These requirements apply to the modified work as a whole. If
133
+ identifiable sections of that work are not derived from the Program,
134
+ and can be reasonably considered independent and separate works in
135
+ themselves, then this License, and its terms, do not apply to those
136
+ sections when you distribute them as separate works. But when you
137
+ distribute the same sections as part of a whole which is a work based
138
+ on the Program, the distribution of the whole must be on the terms of
139
+ this License, whose permissions for other licensees extend to the
140
+ entire whole, and thus to each and every part regardless of who wrote it.
141
+
142
+ Thus, it is not the intent of this section to claim rights or contest
143
+ your rights to work written entirely by you; rather, the intent is to
144
+ exercise the right to control the distribution of derivative or
145
+ collective works based on the Program.
146
+
147
+ In addition, mere aggregation of another work not based on the Program
148
+ with the Program (or with a work based on the Program) on a volume of
149
+ a storage or distribution medium does not bring the other work under
150
+ the scope of this License.
151
+
152
+ 3. You may copy and distribute the Program (or a work based on it,
153
+ under Section 2) in object code or executable form under the terms of
154
+ Sections 1 and 2 above provided that you also do one of the following:
155
+
156
+ a) Accompany it with the complete corresponding machine-readable
157
+ source code, which must be distributed under the terms of Sections
158
+ 1 and 2 above on a medium customarily used for software interchange; or,
159
+
160
+ b) Accompany it with a written offer, valid for at least three
161
+ years, to give any third party, for a charge no more than your
162
+ cost of physically performing source distribution, a complete
163
+ machine-readable copy of the corresponding source code, to be
164
+ distributed under the terms of Sections 1 and 2 above on a medium
165
+ customarily used for software interchange; or,
166
+
167
+ c) Accompany it with the information you received as to the offer
168
+ to distribute corresponding source code. (This alternative is
169
+ allowed only for noncommercial distribution and only if you
170
+ received the program in object code or executable form with such
171
+ an offer, in accord with Subsection b above.)
172
+
173
+ The source code for a work means the preferred form of the work for
174
+ making modifications to it. For an executable work, complete source
175
+ code means all the source code for all modules it contains, plus any
176
+ associated interface definition files, plus the scripts used to
177
+ control compilation and installation of the executable. However, as a
178
+ special exception, the source code distributed need not include
179
+ anything that is normally distributed (in either source or binary
180
+ form) with the major components (compiler, kernel, and so on) of the
181
+ operating system on which the executable runs, unless that component
182
+ itself accompanies the executable.
183
+
184
+ If distribution of executable or object code is made by offering
185
+ access to copy from a designated place, then offering equivalent
186
+ access to copy the source code from the same place counts as
187
+ distribution of the source code, even though third parties are not
188
+ compelled to copy the source along with the object code.
189
+
190
+ 4. You may not copy, modify, sublicense, or distribute the Program
191
+ except as expressly provided under this License. Any attempt
192
+ otherwise to copy, modify, sublicense or distribute the Program is
193
+ void, and will automatically terminate your rights under this License.
194
+ However, parties who have received copies, or rights, from you under
195
+ this License will not have their licenses terminated so long as such
196
+ parties remain in full compliance.
197
+
198
+ 5. You are not required to accept this License, since you have not
199
+ signed it. However, nothing else grants you permission to modify or
200
+ distribute the Program or its derivative works. These actions are
201
+ prohibited by law if you do not accept this License. Therefore, by
202
+ modifying or distributing the Program (or any work based on the
203
+ Program), you indicate your acceptance of this License to do so, and
204
+ all its terms and conditions for copying, distributing or modifying
205
+ the Program or works based on it.
206
+
207
+ 6. Each time you redistribute the Program (or any work based on the
208
+ Program), the recipient automatically receives a license from the
209
+ original licensor to copy, distribute or modify the Program subject to
210
+ these terms and conditions. You may not impose any further
211
+ restrictions on the recipients' exercise of the rights granted herein.
212
+ You are not responsible for enforcing compliance by third parties to
213
+ this License.
214
+
215
+ 7. If, as a consequence of a court judgment or allegation of patent
216
+ infringement or for any other reason (not limited to patent issues),
217
+ conditions are imposed on you (whether by court order, agreement or
218
+ otherwise) that contradict the conditions of this License, they do not
219
+ excuse you from the conditions of this License. If you cannot
220
+ distribute so as to satisfy simultaneously your obligations under this
221
+ License and any other pertinent obligations, then as a consequence you
222
+ may not distribute the Program at all. For example, if a patent
223
+ license would not permit royalty-free redistribution of the Program by
224
+ all those who receive copies directly or indirectly through you, then
225
+ the only way you could satisfy both it and this License would be to
226
+ refrain entirely from distribution of the Program.
227
+
228
+ If any portion of this section is held invalid or unenforceable under
229
+ any particular circumstance, the balance of the section is intended to
230
+ apply and the section as a whole is intended to apply in other
231
+ circumstances.
232
+
233
+ It is not the purpose of this section to induce you to infringe any
234
+ patents or other property right claims or to contest validity of any
235
+ such claims; this section has the sole purpose of protecting the
236
+ integrity of the free software distribution system, which is
237
+ implemented by public license practices. Many people have made
238
+ generous contributions to the wide range of software distributed
239
+ through that system in reliance on consistent application of that
240
+ system; it is up to the author/donor to decide if he or she is willing
241
+ to distribute software through any other system and a licensee cannot
242
+ impose that choice.
243
+
244
+ This section is intended to make thoroughly clear what is believed to
245
+ be a consequence of the rest of this License.
246
+
247
+ 8. If the distribution and/or use of the Program is restricted in
248
+ certain countries either by patents or by copyrighted interfaces, the
249
+ original copyright holder who places the Program under this License
250
+ may add an explicit geographical distribution limitation excluding
251
+ those countries, so that distribution is permitted only in or among
252
+ countries not thus excluded. In such case, this License incorporates
253
+ the limitation as if written in the body of this License.
254
+
255
+ 9. The Free Software Foundation may publish revised and/or new versions
256
+ of the General Public License from time to time. Such new versions will
257
+ be similar in spirit to the present version, but may differ in detail to
258
+ address new problems or concerns.
259
+
260
+ Each version is given a distinguishing version number. If the Program
261
+ specifies a version number of this License which applies to it and "any
262
+ later version", you have the option of following the terms and conditions
263
+ either of that version or of any later version published by the Free
264
+ Software Foundation. If the Program does not specify a version number of
265
+ this License, you may choose any version ever published by the Free Software
266
+ Foundation.
267
+
268
+ 10. If you wish to incorporate parts of the Program into other free
269
+ programs whose distribution conditions are different, write to the author
270
+ to ask for permission. For software which is copyrighted by the Free
271
+ Software Foundation, write to the Free Software Foundation; we sometimes
272
+ make exceptions for this. Our decision will be guided by the two goals
273
+ of preserving the free status of all derivatives of our free software and
274
+ of promoting the sharing and reuse of software generally.
275
+
276
+ NO WARRANTY
277
+
278
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
279
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
280
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
281
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
282
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
283
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
284
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
285
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
286
+ REPAIR OR CORRECTION.
287
+
288
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
289
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
290
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
291
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
292
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
293
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
294
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
295
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
296
+ POSSIBILITY OF SUCH DAMAGES.
297
+
298
+ END OF TERMS AND CONDITIONS
299
+
300
+ How to Apply These Terms to Your New Programs
301
+
302
+ If you develop a new program, and you want it to be of the greatest
303
+ possible use to the public, the best way to achieve this is to make it
304
+ free software which everyone can redistribute and change under these terms.
305
+
306
+ To do so, attach the following notices to the program. It is safest
307
+ to attach them to the start of each source file to most effectively
308
+ convey the exclusion of warranty; and each file should have at least
309
+ the "copyright" line and a pointer to where the full notice is found.
310
+
311
+ <one line to give the program's name and a brief idea of what it does.>
312
+ Copyright (C) <year> <name of author>
313
+
314
+ This program is free software; you can redistribute it and/or modify
315
+ it under the terms of the GNU General Public License as published by
316
+ the Free Software Foundation; either version 2 of the License, or
317
+ (at your option) any later version.
318
+
319
+ This program is distributed in the hope that it will be useful,
320
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
321
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
322
+ GNU General Public License for more details.
323
+
324
+ You should have received a copy of the GNU General Public License along
325
+ with this program; if not, write to the Free Software Foundation, Inc.,
326
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
327
+
328
+ Also add information on how to contact you by electronic and paper mail.
329
+
330
+ If the program is interactive, make it output a short notice like this
331
+ when it starts in an interactive mode:
332
+
333
+ Gnomovision version 69, Copyright (C) year name of author
334
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
335
+ This is free software, and you are welcome to redistribute it
336
+ under certain conditions; type `show c' for details.
337
+
338
+ The hypothetical commands `show w' and `show c' should show the appropriate
339
+ parts of the General Public License. Of course, the commands you use may
340
+ be called something other than `show w' and `show c'; they could even be
341
+ mouse-clicks or menu items--whatever suits your program.
342
+
343
+ You should also get your employer (if you work as a programmer) or your
344
+ school, if any, to sign a "copyright disclaimer" for the program, if
345
+ necessary. Here is a sample; alter the names:
346
+
347
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
348
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
349
+
350
+ <signature of Ty Coon>, 1 April 1989
351
+ Ty Coon, President of Vice
352
+
353
+ This General Public License does not permit incorporating your program into
354
+ proprietary programs. If your program is a subroutine library, you may
355
+ consider it more useful to permit linking proprietary applications with the
356
+ library. If this is what you want to do, use the GNU Lesser General
357
+ Public License instead of this License.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # boost-score-api
2
+
3
+ A package to get the Jetpack Boost score of a site
4
+
5
+ ## How to install boost-score-api
6
+
7
+ Add `"@automattic/jetpack-boost-score-api": "workspace:*",` to your project's `package.json` and run `pnpm install` (or `yarn` if your project uses yarn)
8
+
9
+ ## Using this package in your WordPress plugin
10
+
11
+ If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.
12
+
13
+ ## Security
14
+
15
+ Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic).
16
+
17
+ ## License
18
+
19
+ boost-score-api is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt)
20
+
package/SECURITY.md ADDED
@@ -0,0 +1,38 @@
1
+ # Security Policy
2
+
3
+ Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/).
4
+
5
+ ## Supported Versions
6
+
7
+ Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions.
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ [Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure.
12
+
13
+ **For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.**
14
+
15
+ Our most critical targets are:
16
+
17
+ * Jetpack and the Jetpack composer packages (all within this repo)
18
+ * Jetpack.com -- the primary marketing site.
19
+ * cloud.jetpack.com -- a management site.
20
+ * wordpress.com -- the shared management site for both Jetpack and WordPress.com sites.
21
+
22
+ For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic).
23
+
24
+ _Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._
25
+
26
+ ## Guidelines
27
+
28
+ We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines:
29
+
30
+ * Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
31
+ * Pen-testing Production:
32
+ * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above).
33
+ * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC.
34
+ * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels.
35
+ * To be eligible for a bounty, all of these guidelines must be followed.
36
+ * Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability.
37
+
38
+ We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties.
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ '@automattic/jetpack-webpack-config/babel/preset',
5
+ {
6
+ /* options */
7
+ },
8
+ ],
9
+ ],
10
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@automattic/jetpack-boost-score-api",
3
+ "version": "0.1.0",
4
+ "description": "A package to get the Jetpack Boost score of a site",
5
+ "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/boost-score-api/#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/Automattic/jetpack/labels/[JS Package] Boost Score Api"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/Automattic/jetpack.git",
12
+ "directory": "projects/js-packages/boost-score-api"
13
+ },
14
+ "license": "GPL-2.0-or-later",
15
+ "author": "Automattic",
16
+ "scripts": {
17
+ "build": "pnpm run clean && webpack",
18
+ "clean": "rm -rf build/",
19
+ "watch": "pnpm run build && pnpm webpack watch",
20
+ "test": "jest tests"
21
+ },
22
+ "dependencies": {
23
+ "@wordpress/i18n": "4.32.0",
24
+ "zod": "3.20.2"
25
+ },
26
+ "devDependencies": {
27
+ "@automattic/jetpack-webpack-config": "workspace:*",
28
+ "@typescript-eslint/parser": "5.59.0",
29
+ "eslint": "8.39.0",
30
+ "jest": "29.5.0",
31
+ "ts-loader": "9.4.2",
32
+ "typescript": "5.0.4",
33
+ "webpack": "5.76.0",
34
+ "webpack-cli": "4.9.1"
35
+ },
36
+ "exports": {
37
+ ".": {
38
+ "types": "./build/index.d.ts",
39
+ "default": "./build/index.js"
40
+ }
41
+ },
42
+ "main": "./build/index.js",
43
+ "types": "./build/index.d.ts"
44
+ }
@@ -0,0 +1,65 @@
1
+ import { __, sprintf } from '@wordpress/i18n';
2
+ import { castToString } from './utils/cast-to-string';
3
+ import { isJsonObject } from './utils/json-types';
4
+ import type { JSONObject } from './utils/json-object-type';
5
+
6
+ /**
7
+ * Special error subclass returned by API Calls with extra
8
+ * information.
9
+ */
10
+ export class ApiError extends Error {
11
+ public constructor(
12
+ public readonly httpCode: number,
13
+ public readonly body: JSONObject | string | null,
14
+ public readonly parseError: Error | null
15
+ ) {
16
+ super();
17
+ }
18
+
19
+ // Override Error.message to generate a message based on http code and json body.
20
+ get message(): string {
21
+ switch ( this.httpCode ) {
22
+ case 403: {
23
+ return this.getRestApiErrorMessage();
24
+ }
25
+
26
+ // For HTTP 200 responses, look for JSON parsing issues.
27
+ case 200: {
28
+ if ( this.parseError ) {
29
+ return sprintf(
30
+ /* Translators: %s refers to a browser-supplied error message (hopefully already in the right language) */
31
+ __(
32
+ 'Received invalid response while communicating with your WordPress site: %s',
33
+ 'boost-score-api'
34
+ ),
35
+ this.parseError.message
36
+ );
37
+ }
38
+
39
+ break;
40
+ }
41
+ }
42
+
43
+ return sprintf(
44
+ /* Translators: %d refers to numeric HTTP error code */
45
+ __( 'HTTP %d error received while communicating with the server.', 'boost-score-api' ),
46
+ this.httpCode
47
+ );
48
+ }
49
+
50
+ // Returns the body of this in a string format for display. Pretty printed JSON if valid, raw dump if not.
51
+ public getDisplayBody(): string {
52
+ if ( isJsonObject( this.body ) ) {
53
+ return JSON.stringify( this.body, null, ' ' );
54
+ }
55
+ return castToString( this.body, '' ).substring( 0, 1000 );
56
+ }
57
+
58
+ // Returns an error message appropriate for a site whose API doesn't seem to be available.
59
+ getRestApiErrorMessage(): string {
60
+ return __(
61
+ "Your site's REST API does not seem to be accessible. Jetpack Boost requires access to your REST API in order to receive site performance scores. Please make sure that your site's REST API is active and accessible, and try again.",
62
+ 'boost-score-api'
63
+ );
64
+ }
65
+ }
package/src/api.ts ADDED
@@ -0,0 +1,156 @@
1
+ import { __, sprintf } from '@wordpress/i18n';
2
+ import { ApiError } from './api-error';
3
+ import { JETPACK_BOOST_REST_NAMESPACE, JETPACK_BOOST_REST_PREFIX } from './config';
4
+ import type { JSONObject } from './utils/json-object-type';
5
+
6
+ /**
7
+ * Get the full URL to an endpoint.
8
+ *
9
+ * @param {string} path - The path to the endpoint.
10
+ * @param {string} root - The root URL to use.
11
+ * @returns {string} - The full URL.
12
+ */
13
+ function getEndpointUrl( path: string, root: string ): string {
14
+ return root + JETPACK_BOOST_REST_NAMESPACE + JETPACK_BOOST_REST_PREFIX + path;
15
+ }
16
+
17
+ /**
18
+ * Send a request to the Boost REST API.
19
+ *
20
+ * @param {string} method - The HTTP method to use.
21
+ * @param {string} root - The root URL to use.
22
+ * @param {string} path - The path to the endpoint.
23
+ * @param {null | JSONObject} body - The body of the request.
24
+ * @param {string} nonce - The nonce to use.
25
+ * @returns {Promise} - The response.
26
+ */
27
+ async function sendRequest(
28
+ method: string,
29
+ root: string,
30
+ path: string,
31
+ body: null | JSONObject = null,
32
+ nonce: string
33
+ ): Promise< Response > {
34
+ const args: JSONObject = {
35
+ method,
36
+ mode: 'cors',
37
+ headers: {
38
+ 'X-WP-Nonce': nonce,
39
+ },
40
+ };
41
+
42
+ if ( ( 'post' === method || 'delete' === method ) && body ) {
43
+ args.body = JSON.stringify( body );
44
+ args.headers[ 'Content-Type' ] = 'application/json';
45
+ }
46
+
47
+ const endpointFullUrl = getEndpointUrl( path, root );
48
+ let apiCall: Response;
49
+
50
+ try {
51
+ apiCall = await fetch( endpointFullUrl, args );
52
+ } catch ( error ) {
53
+ const cleanupArgs = args;
54
+ delete cleanupArgs.body;
55
+ delete cleanupArgs.headers[ 'X-WP-Nonce' ];
56
+ const errorInfo = {
57
+ requestInitiator: window.location.href,
58
+ requestUrl: endpointFullUrl,
59
+ requestArgs: cleanupArgs,
60
+ originalErrorMessage: error.toString(),
61
+ };
62
+
63
+ // Throwing again an error so it can be caught higher up and displayed in the UI.
64
+ throw new Error(
65
+ sprintf(
66
+ /* Translators: %s refers to a string representation of an error object containing useful debug information */
67
+ __(
68
+ 'An error occurred while trying to communicate with the site REST API. Extra debug info: %s',
69
+ 'boost-score-api'
70
+ ),
71
+ JSON.stringify( errorInfo )
72
+ )
73
+ );
74
+ }
75
+
76
+ return apiCall;
77
+ }
78
+
79
+ /**
80
+ * Make a request to the Boost REST API.
81
+ *
82
+ * @param {string} method - The HTTP method to use.
83
+ * @param {string} root - The root URL to use.
84
+ * @param {string} path - The path to the endpoint.
85
+ * @param {null | JSONObject} body - The body of the request.
86
+ * @param {string} nonce - The nonce to use.
87
+ * @returns {Promise} - The response.
88
+ */
89
+ async function makeRequest< T = JSONObject >(
90
+ method: string,
91
+ root: string,
92
+ path: string,
93
+ body: null | JSONObject = null,
94
+ nonce: string
95
+ ): Promise< T > {
96
+ const response = await sendRequest( method, root, path, body, nonce );
97
+
98
+ // Fetch response as text.
99
+ let responseBody: string;
100
+ try {
101
+ responseBody = await response.text();
102
+ } catch ( err ) {
103
+ throw new ApiError( response.status, null, err );
104
+ }
105
+
106
+ // Try to parse it as JSON, catch errors explicitly.
107
+ let jsonBody: JSONObject;
108
+ try {
109
+ jsonBody = JSON.parse( responseBody );
110
+ } catch ( err ) {
111
+ throw new ApiError( response.status, responseBody, err );
112
+ }
113
+
114
+ // Throw an error if not HTTP 200.
115
+ if ( ! response.ok ) {
116
+ throw new ApiError( response.status, jsonBody, null );
117
+ }
118
+
119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
+ return jsonBody as any;
121
+ }
122
+
123
+ /**
124
+ * Make a GET request to the Boost REST API.
125
+ *
126
+ * @param {string} root - The root URL to use.
127
+ * @param {string} path - The path to the endpoint.
128
+ * @param {string} nonce - The nonce to use.
129
+ * @returns {Promise} - The response.
130
+ */
131
+ function get< T = JSONObject >( root: string, path: string, nonce: string ): Promise< T > {
132
+ return makeRequest< T >( 'get', root, path, null, nonce );
133
+ }
134
+
135
+ /**
136
+ * Make a POST request to the Boost REST API.
137
+ *
138
+ * @param {string} root - The root URL to use.
139
+ * @param {string} path - The path to the endpoint.
140
+ * @param {null | JSONObject} body - The body of the request.
141
+ * @param {string} nonce - The nonce to use.
142
+ * @returns {Promise} - The response.
143
+ */
144
+ function post< T = JSONObject >(
145
+ root: string,
146
+ path: string,
147
+ body: JSONObject | null = null,
148
+ nonce: string
149
+ ): Promise< T > {
150
+ return makeRequest< T >( 'post', root, path, body, nonce );
151
+ }
152
+
153
+ export default {
154
+ get,
155
+ post,
156
+ };
package/src/config.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const JETPACK_BOOST_REST_NAMESPACE = 'jetpack-boost/v1';
2
+ export const JETPACK_BOOST_REST_PREFIX = '';
package/src/index.ts ADDED
@@ -0,0 +1,220 @@
1
+ import { __ } from '@wordpress/i18n';
2
+ import api from './api';
3
+ import { castToNumber } from './utils/cast-to-number';
4
+ import { castToString } from './utils/cast-to-string';
5
+ import { isJsonObject, JSONObject } from './utils/json-types';
6
+ import pollPromise from './utils/poll-promise';
7
+ import { standardizeError } from './utils/standardize-error';
8
+
9
+ const pollTimeout = 2 * 60 * 1000;
10
+ const pollInterval = 5 * 1000;
11
+
12
+ type SpeedScores = {
13
+ mobile: number;
14
+ desktop: number;
15
+ };
16
+
17
+ type SpeedScoresSet = {
18
+ current: SpeedScores;
19
+ noBoost: SpeedScores;
20
+ isStale: boolean;
21
+ };
22
+
23
+ type ParsedApiResponse = {
24
+ status: string;
25
+ scores?: SpeedScoresSet;
26
+ };
27
+
28
+ /**
29
+ * Kick off a request to generate speed scores for this site. Will automatically
30
+ * poll for a response until the task is done, returning a SpeedScores object.
31
+ *
32
+ * @param {boolean} force - Force regenerate speed scores.
33
+ * @param {string} rootUrl - Root URL for the HTTP request.
34
+ * @param {string} siteUrl - URL of the site.
35
+ * @param {string} nonce - Nonce to use for authentication.
36
+ * @returns {SpeedScoresSet} Speed scores returned by the server.
37
+ */
38
+ export async function requestSpeedScores(
39
+ force = false,
40
+ rootUrl: string,
41
+ siteUrl: string,
42
+ nonce: string
43
+ ): Promise< SpeedScoresSet > {
44
+ // Request metrics
45
+ const response = parseResponse(
46
+ await api.post(
47
+ rootUrl,
48
+ force ? '/speed-scores/refresh' : '/speed-scores',
49
+ { url: siteUrl },
50
+ nonce
51
+ )
52
+ );
53
+
54
+ // If the response contains ready-to-use metrics, we're done here.
55
+ if ( response.scores ) {
56
+ return response.scores;
57
+ }
58
+
59
+ // Poll for metrics.
60
+ return await pollRequest( rootUrl, siteUrl, nonce );
61
+ }
62
+
63
+ /**
64
+ * Helper method for parsing a response from a speed score API request. Returns
65
+ * scores (if ready), and a status (success|pending|error).
66
+ *
67
+ * @param {JSONObject} response - API response to parse
68
+ * @returns {ParsedApiResponse} API response, processed.
69
+ */
70
+ function parseResponse( response: JSONObject ): ParsedApiResponse {
71
+ // Handle an explicit error
72
+ if ( response.error ) {
73
+ const defaultErrorMessage = __(
74
+ 'An unknown error occurred while requesting metrics',
75
+ 'boost-score-api'
76
+ );
77
+
78
+ throw standardizeError( response.error, defaultErrorMessage );
79
+ }
80
+
81
+ // Check if ready.
82
+ if ( isJsonObject( response.scores ) ) {
83
+ return {
84
+ status: 'success',
85
+ scores: {
86
+ current: isJsonObject( response.scores.current )
87
+ ? {
88
+ mobile: castToNumber( response.scores.current.mobile, 0 ),
89
+ desktop: castToNumber( response.scores.current.desktop, 0 ),
90
+ }
91
+ : {
92
+ mobile: 0,
93
+ desktop: 0,
94
+ },
95
+ noBoost: isJsonObject( response.scores.noBoost )
96
+ ? {
97
+ mobile: castToNumber( response.scores.noBoost.mobile, 0 ),
98
+ desktop: castToNumber( response.scores.noBoost.desktop, 0 ),
99
+ }
100
+ : null,
101
+ isStale: !! response.scores.isStale,
102
+ },
103
+ };
104
+ }
105
+
106
+ const requestStatus = castToString( response.status );
107
+ if ( ! requestStatus ) {
108
+ throw new Error( __( 'Invalid response while requesting metrics', 'boost-score-api' ) );
109
+ }
110
+
111
+ return {
112
+ status: requestStatus,
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Poll a speed score request for results, timing out if it takes too long.
118
+ *
119
+ * @param {string} rootUrl - Root URL of the site to request metrics for
120
+ * @param {string} siteUrl - Site URL to request metrics for
121
+ * @param {string} nonce - Nonce to use for authentication
122
+ * @returns {SpeedScoresSet} Speed scores returned by the server.
123
+ */
124
+ async function pollRequest(
125
+ rootUrl: string,
126
+ siteUrl: string,
127
+ nonce: string
128
+ ): Promise< SpeedScoresSet > {
129
+ return pollPromise< SpeedScoresSet >( {
130
+ timeout: pollTimeout,
131
+ interval: pollInterval,
132
+ timeoutError: __( 'Timed out while waiting for speed-score.', 'boost-score-api' ),
133
+ callback: async resolve => {
134
+ const response = parseResponse(
135
+ await api.post( rootUrl, '/speed-scores', { url: siteUrl }, nonce )
136
+ );
137
+
138
+ if ( response.scores ) {
139
+ resolve( response.scores );
140
+ }
141
+ },
142
+ } );
143
+ }
144
+
145
+ /**
146
+ * Given a mobile and desktop score, return a letter summarizing the overall
147
+ * score.
148
+ *
149
+ * @param {number} mobile - Mobile speed score
150
+ * @param {number} desktop - Desktop speed score
151
+ * @returns {string} letter score
152
+ */
153
+ export function getScoreLetter( mobile: number, desktop: number ): string {
154
+ const sum = mobile + desktop;
155
+ const averageScore = sum / 2;
156
+
157
+ if ( averageScore > 90 ) {
158
+ return 'A';
159
+ }
160
+ if ( averageScore > 75 ) {
161
+ return 'B';
162
+ }
163
+ if ( averageScore > 50 ) {
164
+ return 'C';
165
+ }
166
+ if ( averageScore > 35 ) {
167
+ return 'D';
168
+ }
169
+ if ( averageScore > 25 ) {
170
+ return 'E';
171
+ }
172
+ return 'F';
173
+ }
174
+
175
+ /**
176
+ * Find out if site scores changed. We fire a popout modal if they improve or worsen.
177
+ * The message varies depending on the results of the speed scores so lets modify this
178
+ *
179
+ * @param {SpeedScoresSet} scores - Speed scores returned by the server.
180
+ * @returns {boolean} true if scores changed.
181
+ */
182
+ export function didScoresChange( scores: SpeedScoresSet ): boolean {
183
+ const current = scores.current;
184
+ const noBoost = scores.noBoost;
185
+
186
+ // lets make this a little bit more readable. If one of the scores is null.
187
+ // then the scores haven't changed. So return false.
188
+ if ( null == current || null == noBoost ) {
189
+ return false;
190
+ }
191
+
192
+ // if either the mobile or the desktop scores have changed. Return true.
193
+ if ( current.mobile !== noBoost.mobile || current.desktop !== noBoost.desktop ) {
194
+ return true;
195
+ }
196
+
197
+ //else if reach here then the scores are the same.
198
+ return false;
199
+ }
200
+
201
+ /**
202
+ * Determine the change in scores to pass through to other functions.
203
+ *
204
+ * @param {SpeedScoresSet} scores - Speed scores returned by the server.
205
+ * @returns {number} - The change in scores in percentage.
206
+ */
207
+ export function getScoreMovementPercentage( scores: SpeedScoresSet ): number {
208
+ const current = scores.current;
209
+ const noBoost = scores.noBoost;
210
+ let currentScore = 0;
211
+ let noBoostScore = 0;
212
+
213
+ if ( current !== null && noBoost !== null ) {
214
+ currentScore = scores.current.mobile + scores.current.desktop;
215
+ noBoostScore = scores.noBoost.mobile + scores.noBoost.desktop;
216
+ const change = currentScore / noBoostScore - 1;
217
+ return Math.round( change * 100 );
218
+ }
219
+ return 0;
220
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Given an unknown value from an external source (e.g.: API response), parse
3
+ * it as a number. Returns defaultValue if the value does not seem to be a valid
4
+ * number.
5
+ *
6
+ * @template DefaultType
7
+ * @param {*} value - External value to process as a number
8
+ * @param {DefaultType} defaultValue - Default value to return if not a number.
9
+ * @returns {number | DefaultType} value as a number, of defaultValue.
10
+ */
11
+ export function castToNumber< DefaultType = number >(
12
+ value: unknown,
13
+ defaultValue: DefaultType = undefined
14
+ ): number | DefaultType {
15
+ if ( typeof value === 'number' ) {
16
+ return value;
17
+ }
18
+
19
+ if ( typeof value === 'string' ) {
20
+ const float = parseFloat( value );
21
+ if ( ! isNaN( float ) ) {
22
+ return float;
23
+ }
24
+ }
25
+
26
+ return defaultValue;
27
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Given an unknown value from an external source (e.g.: API response), parse
3
+ * it as a string. Returns defaultValue if the value does not seem to be a valid
4
+ * string.
5
+ *
6
+ * @template DefaultType
7
+ * @param {*} value - External value to process as a string
8
+ * @param {DefaultType} defaultValue - Default value to return if not a string
9
+ * @returns {string | DefaultType} value as a string, of defaultValue.
10
+ */
11
+ export function castToString< DefaultType = undefined >(
12
+ value: unknown,
13
+ defaultValue: DefaultType | undefined = undefined
14
+ ): string | DefaultType | undefined {
15
+ if ( typeof value === 'string' ) {
16
+ return value;
17
+ }
18
+
19
+ if ( ! value ) {
20
+ return defaultValue;
21
+ }
22
+
23
+ if ( value.toString instanceof Function ) {
24
+ return value.toString();
25
+ }
26
+
27
+ return defaultValue;
28
+ }
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Definition for JSON types:
5
+ * - JSONValue can be any value compatible with JSON; an object (containing JSONValues), array, string, number, boolean, or null
6
+ * - JSONObject is an object containing JSONValues
7
+ * - JSONSchema is a zod schema that can be used to validate JSONValues
8
+ */
9
+ const literalSchema = z.union( [ z.string(), z.number(), z.boolean(), z.null() ] );
10
+ type Literal = z.infer< typeof literalSchema >;
11
+ export type JSONValue = Literal | JSONObject | JSONValue[];
12
+ export type JSONObject = { [ key: string ]: JSONValue };
@@ -0,0 +1,32 @@
1
+ /* eslint-disable no-use-before-define */
2
+ /**
3
+ * Generic type for handling JSON-like objects.
4
+ *
5
+ * Use this as a last resort if you can't reasonably describe the possible shapes an object can take.
6
+ */
7
+ export type JSONObject = {
8
+ [ key: string ]: JSONValue;
9
+ };
10
+ export type JSONArray = JSONValue[];
11
+ export type JSONValue = string | number | boolean | JSONObject | JSONArray | null | undefined;
12
+
13
+ /**
14
+ * Returns true if the given JSONValue is a JSONObject.
15
+ *
16
+ * @param {JSONValue} value - Value to check.
17
+ * @returns {boolean} True if the given value is a JSONObject.
18
+ */
19
+ export function isJsonObject( value: JSONValue ): value is JSONObject {
20
+ return !! value && value instanceof Object && ! ( value instanceof Array );
21
+ }
22
+
23
+ /**
24
+ * Returns true if the given JSONValue is a JSONArray.
25
+ * Sure, you could use x instanceof Array but this is shorter and more consistent.
26
+ *
27
+ * @param {JSONValue} value - Value to check.
28
+ * @returns {boolean} True if the given value is a JSONArray.
29
+ */
30
+ export function isJsonArray( value: JSONValue ): value is JSONArray {
31
+ return value instanceof Array;
32
+ }
@@ -0,0 +1,51 @@
1
+ import { __ } from '@wordpress/i18n';
2
+
3
+ type Resolve< ReturnType = void > = ( value: ReturnType | PromiseLike< ReturnType > ) => void;
4
+
5
+ type PollPromiseArgs< ReturnType = void > = {
6
+ interval: number;
7
+ timeout: number;
8
+ timeoutError?: string;
9
+ callback: ( resolve: Resolve< ReturnType > ) => Promise< void > | void;
10
+ };
11
+
12
+ /**
13
+ * Repeatedly poll callback every <interval> milliseconds until it calls the
14
+ * resolve() callback. If the callback throws an error, the whole polling
15
+ * promise will reject.
16
+ *
17
+ * Rejects with a timeout after <timeout> milliseconds.
18
+ *
19
+ * @template ReturnType
20
+ * @param {object} obj - Arguments object.
21
+ * @param {number} obj.interval - Milliseconds between calling callback
22
+ * @param {number} obj.timeout - Milliseconds before rejecting w/ a timeout
23
+ * @param {Function} obj.callback - Callback to call every <interval> ms.
24
+ * @param {string} obj.timeoutError - Message to throw on timeout.
25
+ * @returns {Promise< ReturnType >} - A promise which resolves to the value resolved() inside callback.
26
+ */
27
+ export default async function pollPromise< ReturnType = void >( {
28
+ interval,
29
+ callback,
30
+ timeout,
31
+ timeoutError,
32
+ }: PollPromiseArgs< ReturnType > ): Promise< ReturnType > {
33
+ let timeoutHandle: number, intervalHandle: number;
34
+
35
+ return new Promise< ReturnType >( ( resolve, reject ) => {
36
+ timeoutHandle = setTimeout( () => {
37
+ reject( new Error( timeoutError || __( 'Timed out', 'boost-score-api' ) ) );
38
+ }, timeout || 2 * 60 * 1000 );
39
+
40
+ intervalHandle = setInterval( async () => {
41
+ try {
42
+ await Promise.resolve( callback( resolve ) );
43
+ } catch ( err ) {
44
+ reject( err );
45
+ }
46
+ }, interval );
47
+ } ).finally( () => {
48
+ clearTimeout( timeoutHandle );
49
+ clearInterval( intervalHandle );
50
+ } );
51
+ }
@@ -0,0 +1,33 @@
1
+ import type { JSONValue } from './json-types';
2
+
3
+ /**
4
+ * JavaScript offers no guarantee that caught objects in catch blocks are actually
5
+ * Error objects. This method fixes that, for type safety. :)
6
+ *
7
+ * @param {*} data - Any thrown error data to interpret as an Error (or subclass)
8
+ * @param {JSONValue|Error} defaultMessage - A default message to throw if no sensible error can be found.
9
+ * @returns {Error} the data guaranteed to be an Error or subclass thereof.
10
+ */
11
+ export function standardizeError( data: JSONValue | Error, defaultMessage?: string ): Error {
12
+ if ( data instanceof Error ) {
13
+ return data;
14
+ }
15
+
16
+ if ( typeof data === 'string' || data instanceof String ) {
17
+ return new Error( data.toString() );
18
+ }
19
+
20
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21
+ // @ts-ignore
22
+ if ( data.message ) {
23
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24
+ // @ts-ignore
25
+ return new Error( data.message );
26
+ }
27
+
28
+ if ( defaultMessage ) {
29
+ return new Error( defaultMessage );
30
+ }
31
+
32
+ return new Error( JSON.stringify( data ) );
33
+ }
@@ -0,0 +1,34 @@
1
+ const path = require( 'path' );
2
+ const jetpackWebpackConfig = require( '@automattic/jetpack-webpack-config/webpack' );
3
+
4
+ module.exports = {
5
+ entry: './src/index.ts',
6
+ mode: jetpackWebpackConfig.mode,
7
+ devtool: jetpackWebpackConfig.isProduction ? false : 'source-map',
8
+ module: {
9
+ strictExportPresence: true,
10
+ rules: [
11
+ {
12
+ test: /\.ts?$/,
13
+ use: 'ts-loader',
14
+ exclude: /node_modules/,
15
+ },
16
+ ],
17
+ },
18
+ optimization: {
19
+ ...jetpackWebpackConfig.optimization,
20
+ },
21
+ resolve: {
22
+ ...jetpackWebpackConfig.resolve,
23
+ },
24
+ output: {
25
+ ...jetpackWebpackConfig.output,
26
+ path: path.resolve( __dirname, 'build' ),
27
+ filename: 'index.js',
28
+ library: {
29
+ name: 'BoostScoreApiLibrary',
30
+ type: 'umd',
31
+ },
32
+ },
33
+ plugins: [ ...jetpackWebpackConfig.StandardPlugins() ],
34
+ };