@backstage-community/plugin-lighthouse-common 0.1.9 → 0.1.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @backstage-community/plugin-lighthouse-common
2
2
 
3
+ ## 0.1.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 60d3a5d: Backstage version bump to v1.32.2
8
+
3
9
  ## 0.1.9
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ class FetchError extends Error {
4
+ get name() {
5
+ return this.constructor.name;
6
+ }
7
+ static async forResponse(resp) {
8
+ return new FetchError(
9
+ `Request failed with status code ${resp.status}.
10
+ Reason: ${await resp.text()}`
11
+ );
12
+ }
13
+ }
14
+ class LighthouseRestApi {
15
+ constructor(url) {
16
+ this.url = url;
17
+ }
18
+ static fromConfig(config) {
19
+ return new LighthouseRestApi(config.getString("lighthouse.baseUrl"));
20
+ }
21
+ async fetch(input, init) {
22
+ const resp = await fetch(`${this.url}${input}`, init);
23
+ if (!resp.ok) throw await FetchError.forResponse(resp);
24
+ return await resp.json();
25
+ }
26
+ async getWebsiteList(options = {}) {
27
+ const { limit, offset } = options;
28
+ const params = new URLSearchParams();
29
+ if (typeof limit === "number") params.append("limit", limit.toString());
30
+ if (typeof offset === "number") params.append("offset", offset.toString());
31
+ return await this.fetch(
32
+ `/v1/websites?${params.toString()}`
33
+ );
34
+ }
35
+ async getWebsiteForAuditId(auditId) {
36
+ return await this.fetch(
37
+ `/v1/audits/${encodeURIComponent(auditId)}/website`
38
+ );
39
+ }
40
+ async triggerAudit(payload) {
41
+ return await this.fetch("/v1/audits", {
42
+ method: "POST",
43
+ body: JSON.stringify(payload),
44
+ headers: {
45
+ "Content-Type": "application/json"
46
+ }
47
+ });
48
+ }
49
+ async getWebsiteByUrl(websiteUrl) {
50
+ return this.fetch(
51
+ `/v1/websites/${encodeURIComponent(websiteUrl)}`
52
+ );
53
+ }
54
+ }
55
+
56
+ exports.FetchError = FetchError;
57
+ exports.LighthouseRestApi = LighthouseRestApi;
58
+ //# sourceMappingURL=api.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.cjs.js","sources":["../src/api.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\n\n/** @public */\nexport type LighthouseCategoryId =\n | 'pwa'\n | 'seo'\n | 'performance'\n | 'accessibility'\n | 'best-practices';\n\n/** @public */\nexport interface LighthouseCategoryAbbr {\n id: LighthouseCategoryId;\n score: number;\n title: string;\n}\n\n/** @public */\nexport interface LASListRequest {\n offset?: number;\n limit?: number;\n}\n\n/** @public */\nexport interface LASListResponse<Item> {\n items: Item[];\n total: number;\n offset: number;\n limit: number;\n}\n\n/** @public */\nexport interface AuditBase {\n id: string;\n url: string;\n timeCreated: string;\n}\n\n/** @public */\nexport interface AuditRunning extends AuditBase {\n status: 'RUNNING';\n}\n\n/** @public */\nexport interface AuditFailed extends AuditBase {\n status: 'FAILED';\n timeCompleted: string;\n}\n\n/** @public */\nexport interface AuditCompleted extends AuditBase {\n status: 'COMPLETED';\n timeCompleted: string;\n report: Object;\n categories: Record<LighthouseCategoryId, LighthouseCategoryAbbr>;\n}\n\n/** @public */\nexport type Audit = AuditRunning | AuditFailed | AuditCompleted;\n\n/** @public */\nexport interface Website {\n url: string;\n audits: Audit[];\n lastAudit: Audit;\n}\n\n/** @public */\nexport type WebsiteListResponse = LASListResponse<Website>;\n\n/** @public */\nexport type FormFactor = 'mobile' | 'desktop';\n\n/** @public */\nexport type LighthouseConfigSettings = {\n // For lighthouse 7+\n formFactor: FormFactor;\n screenEmulation:\n | {\n mobile: boolean;\n width: number;\n height: number;\n deviceScaleFactor: number;\n disabled: boolean;\n }\n | undefined;\n // For lighthouse before 7\n emulatedFormFactor: FormFactor;\n};\n\n/** @public */\nexport interface TriggerAuditPayload {\n url: string;\n options: {\n lighthouseConfig: {\n settings: LighthouseConfigSettings;\n };\n };\n}\n\n/** @public */\nexport class FetchError extends Error {\n get name(): string {\n return this.constructor.name;\n }\n\n static async forResponse(resp: Response): Promise<FetchError> {\n return new FetchError(\n `Request failed with status code ${\n resp.status\n }.\\nReason: ${await resp.text()}`,\n );\n }\n}\n\n/** @public */\nexport type LighthouseApi = {\n url: string;\n getWebsiteList: (listOptions: LASListRequest) => Promise<WebsiteListResponse>;\n getWebsiteForAuditId: (auditId: string) => Promise<Website>;\n triggerAudit: (payload: TriggerAuditPayload) => Promise<Audit>;\n getWebsiteByUrl: (websiteUrl: string) => Promise<Website>;\n};\n\n/** @public */\nexport class LighthouseRestApi implements LighthouseApi {\n static fromConfig(config: Config) {\n return new LighthouseRestApi(config.getString('lighthouse.baseUrl'));\n }\n\n constructor(public url: string) {}\n\n private async fetch<T = any>(input: string, init?: RequestInit): Promise<T> {\n const resp = await fetch(`${this.url}${input}`, init);\n if (!resp.ok) throw await FetchError.forResponse(resp);\n return await resp.json();\n }\n\n async getWebsiteList(\n options: LASListRequest = {},\n ): Promise<WebsiteListResponse> {\n const { limit, offset } = options;\n const params = new URLSearchParams();\n if (typeof limit === 'number') params.append('limit', limit.toString());\n if (typeof offset === 'number') params.append('offset', offset.toString());\n return await this.fetch<WebsiteListResponse>(\n `/v1/websites?${params.toString()}`,\n );\n }\n\n async getWebsiteForAuditId(auditId: string): Promise<Website> {\n return await this.fetch<Website>(\n `/v1/audits/${encodeURIComponent(auditId)}/website`,\n );\n }\n\n async triggerAudit(payload: TriggerAuditPayload): Promise<Audit> {\n return await this.fetch<Audit>('/v1/audits', {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n }\n\n async getWebsiteByUrl(websiteUrl: string): Promise<Website> {\n return this.fetch<Website>(\n `/v1/websites/${encodeURIComponent(websiteUrl)}`,\n );\n }\n}\n"],"names":[],"mappings":";;AAqHO,MAAM,mBAAmB,KAAM,CAAA;AAAA,EACpC,IAAI,IAAe,GAAA;AACjB,IAAA,OAAO,KAAK,WAAY,CAAA,IAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,aAAa,YAAY,IAAqC,EAAA;AAC5D,IAAA,OAAO,IAAI,UAAA;AAAA,MACT,CAAA,gCAAA,EACE,KAAK,MACP,CAAA;AAAA,QAAc,EAAA,MAAM,IAAK,CAAA,IAAA,EAAM,CAAA,CAAA;AAAA,KACjC,CAAA;AAAA,GACF;AACF,CAAA;AAYO,MAAM,iBAA2C,CAAA;AAAA,EAKtD,YAAmB,GAAa,EAAA;AAAb,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA,CAAA;AAAA,GAAc;AAAA,EAJjC,OAAO,WAAW,MAAgB,EAAA;AAChC,IAAA,OAAO,IAAI,iBAAA,CAAkB,MAAO,CAAA,SAAA,CAAU,oBAAoB,CAAC,CAAA,CAAA;AAAA,GACrE;AAAA,EAIA,MAAc,KAAe,CAAA,KAAA,EAAe,IAAgC,EAAA;AAC1E,IAAM,MAAA,IAAA,GAAO,MAAM,KAAM,CAAA,CAAA,EAAG,KAAK,GAAG,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AACpD,IAAA,IAAI,CAAC,IAAK,CAAA,EAAA,QAAU,MAAM,UAAA,CAAW,YAAY,IAAI,CAAA,CAAA;AACrD,IAAO,OAAA,MAAM,KAAK,IAAK,EAAA,CAAA;AAAA,GACzB;AAAA,EAEA,MAAM,cAAA,CACJ,OAA0B,GAAA,EACI,EAAA;AAC9B,IAAM,MAAA,EAAE,KAAO,EAAA,MAAA,EAAW,GAAA,OAAA,CAAA;AAC1B,IAAM,MAAA,MAAA,GAAS,IAAI,eAAgB,EAAA,CAAA;AACnC,IAAI,IAAA,OAAO,UAAU,QAAU,EAAA,MAAA,CAAO,OAAO,OAAS,EAAA,KAAA,CAAM,UAAU,CAAA,CAAA;AACtE,IAAI,IAAA,OAAO,WAAW,QAAU,EAAA,MAAA,CAAO,OAAO,QAAU,EAAA,MAAA,CAAO,UAAU,CAAA,CAAA;AACzE,IAAA,OAAO,MAAM,IAAK,CAAA,KAAA;AAAA,MAChB,CAAA,aAAA,EAAgB,MAAO,CAAA,QAAA,EAAU,CAAA,CAAA;AAAA,KACnC,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,qBAAqB,OAAmC,EAAA;AAC5D,IAAA,OAAO,MAAM,IAAK,CAAA,KAAA;AAAA,MAChB,CAAA,WAAA,EAAc,kBAAmB,CAAA,OAAO,CAAC,CAAA,QAAA,CAAA;AAAA,KAC3C,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,aAAa,OAA8C,EAAA;AAC/D,IAAO,OAAA,MAAM,IAAK,CAAA,KAAA,CAAa,YAAc,EAAA;AAAA,MAC3C,MAAQ,EAAA,MAAA;AAAA,MACR,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,OAAO,CAAA;AAAA,MAC5B,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,OAClB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,gBAAgB,UAAsC,EAAA;AAC1D,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA,MACV,CAAA,aAAA,EAAgB,kBAAmB,CAAA,UAAU,CAAC,CAAA,CAAA;AAAA,KAChD,CAAA;AAAA,GACF;AACF;;;;;"}
package/dist/index.cjs.js CHANGED
@@ -1,58 +1,9 @@
1
1
  'use strict';
2
2
 
3
- class FetchError extends Error {
4
- get name() {
5
- return this.constructor.name;
6
- }
7
- static async forResponse(resp) {
8
- return new FetchError(
9
- `Request failed with status code ${resp.status}.
10
- Reason: ${await resp.text()}`
11
- );
12
- }
13
- }
14
- class LighthouseRestApi {
15
- constructor(url) {
16
- this.url = url;
17
- }
18
- static fromConfig(config) {
19
- return new LighthouseRestApi(config.getString("lighthouse.baseUrl"));
20
- }
21
- async fetch(input, init) {
22
- const resp = await fetch(`${this.url}${input}`, init);
23
- if (!resp.ok) throw await FetchError.forResponse(resp);
24
- return await resp.json();
25
- }
26
- async getWebsiteList(options = {}) {
27
- const { limit, offset } = options;
28
- const params = new URLSearchParams();
29
- if (typeof limit === "number") params.append("limit", limit.toString());
30
- if (typeof offset === "number") params.append("offset", offset.toString());
31
- return await this.fetch(
32
- `/v1/websites?${params.toString()}`
33
- );
34
- }
35
- async getWebsiteForAuditId(auditId) {
36
- return await this.fetch(
37
- `/v1/audits/${encodeURIComponent(auditId)}/website`
38
- );
39
- }
40
- async triggerAudit(payload) {
41
- return await this.fetch("/v1/audits", {
42
- method: "POST",
43
- body: JSON.stringify(payload),
44
- headers: {
45
- "Content-Type": "application/json"
46
- }
47
- });
48
- }
49
- async getWebsiteByUrl(websiteUrl) {
50
- return this.fetch(
51
- `/v1/websites/${encodeURIComponent(websiteUrl)}`
52
- );
53
- }
54
- }
3
+ var api = require('./api.cjs.js');
55
4
 
56
- exports.FetchError = FetchError;
57
- exports.LighthouseRestApi = LighthouseRestApi;
5
+
6
+
7
+ exports.FetchError = api.FetchError;
8
+ exports.LighthouseRestApi = api.LighthouseRestApi;
58
9
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/api.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\n\n/** @public */\nexport type LighthouseCategoryId =\n | 'pwa'\n | 'seo'\n | 'performance'\n | 'accessibility'\n | 'best-practices';\n\n/** @public */\nexport interface LighthouseCategoryAbbr {\n id: LighthouseCategoryId;\n score: number;\n title: string;\n}\n\n/** @public */\nexport interface LASListRequest {\n offset?: number;\n limit?: number;\n}\n\n/** @public */\nexport interface LASListResponse<Item> {\n items: Item[];\n total: number;\n offset: number;\n limit: number;\n}\n\n/** @public */\nexport interface AuditBase {\n id: string;\n url: string;\n timeCreated: string;\n}\n\n/** @public */\nexport interface AuditRunning extends AuditBase {\n status: 'RUNNING';\n}\n\n/** @public */\nexport interface AuditFailed extends AuditBase {\n status: 'FAILED';\n timeCompleted: string;\n}\n\n/** @public */\nexport interface AuditCompleted extends AuditBase {\n status: 'COMPLETED';\n timeCompleted: string;\n report: Object;\n categories: Record<LighthouseCategoryId, LighthouseCategoryAbbr>;\n}\n\n/** @public */\nexport type Audit = AuditRunning | AuditFailed | AuditCompleted;\n\n/** @public */\nexport interface Website {\n url: string;\n audits: Audit[];\n lastAudit: Audit;\n}\n\n/** @public */\nexport type WebsiteListResponse = LASListResponse<Website>;\n\n/** @public */\nexport type FormFactor = 'mobile' | 'desktop';\n\n/** @public */\nexport type LighthouseConfigSettings = {\n // For lighthouse 7+\n formFactor: FormFactor;\n screenEmulation:\n | {\n mobile: boolean;\n width: number;\n height: number;\n deviceScaleFactor: number;\n disabled: boolean;\n }\n | undefined;\n // For lighthouse before 7\n emulatedFormFactor: FormFactor;\n};\n\n/** @public */\nexport interface TriggerAuditPayload {\n url: string;\n options: {\n lighthouseConfig: {\n settings: LighthouseConfigSettings;\n };\n };\n}\n\n/** @public */\nexport class FetchError extends Error {\n get name(): string {\n return this.constructor.name;\n }\n\n static async forResponse(resp: Response): Promise<FetchError> {\n return new FetchError(\n `Request failed with status code ${\n resp.status\n }.\\nReason: ${await resp.text()}`,\n );\n }\n}\n\n/** @public */\nexport type LighthouseApi = {\n url: string;\n getWebsiteList: (listOptions: LASListRequest) => Promise<WebsiteListResponse>;\n getWebsiteForAuditId: (auditId: string) => Promise<Website>;\n triggerAudit: (payload: TriggerAuditPayload) => Promise<Audit>;\n getWebsiteByUrl: (websiteUrl: string) => Promise<Website>;\n};\n\n/** @public */\nexport class LighthouseRestApi implements LighthouseApi {\n static fromConfig(config: Config) {\n return new LighthouseRestApi(config.getString('lighthouse.baseUrl'));\n }\n\n constructor(public url: string) {}\n\n private async fetch<T = any>(input: string, init?: RequestInit): Promise<T> {\n const resp = await fetch(`${this.url}${input}`, init);\n if (!resp.ok) throw await FetchError.forResponse(resp);\n return await resp.json();\n }\n\n async getWebsiteList(\n options: LASListRequest = {},\n ): Promise<WebsiteListResponse> {\n const { limit, offset } = options;\n const params = new URLSearchParams();\n if (typeof limit === 'number') params.append('limit', limit.toString());\n if (typeof offset === 'number') params.append('offset', offset.toString());\n return await this.fetch<WebsiteListResponse>(\n `/v1/websites?${params.toString()}`,\n );\n }\n\n async getWebsiteForAuditId(auditId: string): Promise<Website> {\n return await this.fetch<Website>(\n `/v1/audits/${encodeURIComponent(auditId)}/website`,\n );\n }\n\n async triggerAudit(payload: TriggerAuditPayload): Promise<Audit> {\n return await this.fetch<Audit>('/v1/audits', {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n }\n\n async getWebsiteByUrl(websiteUrl: string): Promise<Website> {\n return this.fetch<Website>(\n `/v1/websites/${encodeURIComponent(websiteUrl)}`,\n );\n }\n}\n"],"names":[],"mappings":";;AAqHO,MAAM,mBAAmB,KAAM,CAAA;AAAA,EACpC,IAAI,IAAe,GAAA;AACjB,IAAA,OAAO,KAAK,WAAY,CAAA,IAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,aAAa,YAAY,IAAqC,EAAA;AAC5D,IAAA,O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U,CAAA,CAAA;AAAA,KACnC,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,qBAAqB,OAAmC,EAAA;AAC5D,IAAA,OAAO,MAAM,IAAK,CAAA,KAAA;AAAA,MAChB,CAAA,WAAA,EAAc,kBAAmB,CAAA,OAAO,CAAC,CAAA,QAAA,CAAA;AAAA,KAC3C,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,aAAa,OAA8C,EAAA;AAC/D,IAAO,OAAA,MAAM,IAAK,CAAA,KAAA,CAAa,YAAc,EAAA;AAAA,MAC3C,MAAQ,EAAA,MAAA;AAAA,MACR,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,OAAO,CAAA;AAAA,MAC5B,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,OAClB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,gBAAgB,UAAsC,EAAA;AAC1D,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA,MACV,CAAA,aAAA,EAAgB,kBAAmB,CAAA,UAAU,CAAC,CAAA,CAAA;AAAA,KAChD,CAAA;AAAA,GACF;AACF;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage-community/plugin-lighthouse-common",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Common functionalities for lighthouse, to be shared between lighthouse and lighthouse-backend plugin",
5
5
  "backstage": {
6
6
  "role": "common-library",
@@ -48,7 +48,7 @@
48
48
  "@backstage/config": "^1.2.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@backstage/cli": "^0.27.1"
51
+ "@backstage/cli": "^0.28.0"
52
52
  },
53
53
  "module": "dist/index.esm.js"
54
54
  }