diff --git a/package-lock.json b/package-lock.json index ab713135cbcd7..e5d8c1b3f6708 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,7 +55,7 @@ "smol-toml": "1.3.0", "svg-path-bbox": "^2.1.0", "svgpath": "^2.6.0", - "webextension-store-meta": "^1.2.3", + "webextension-store-meta": "^1.2.4", "xpath": "~0.0.34" }, "devDependencies": { @@ -29801,9 +29801,10 @@ } }, "node_modules/webextension-store-meta": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/webextension-store-meta/-/webextension-store-meta-1.2.3.tgz", - "integrity": "sha512-CpIiG/zCwdUBce6O4E4q/9EHC3p5/JxtD+cYWVPZCTjKbuSasfbLzFV5i+QPXEVoChW6jcg6OWdgSDtDfvCHIA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/webextension-store-meta/-/webextension-store-meta-1.2.4.tgz", + "integrity": "sha512-cyFEPs277pjm3FgLbfAzRxr7LkVKw5fzQmO/wcXN7i7/03nnMcB24OjVyot+ZT0OWknLsHs5ef6jlWzoK9A2tA==", + "license": "MIT", "dependencies": { "domhandler": "^4.0.0", "htmlparser2": "^6.1.0", diff --git a/package.json b/package.json index c2ff907d9774d..3b548719cd226 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "smol-toml": "1.3.0", "svg-path-bbox": "^2.1.0", "svgpath": "^2.6.0", - "webextension-store-meta": "^1.2.3", + "webextension-store-meta": "^1.2.4", "xpath": "~0.0.34" }, "scripts": { diff --git a/services/chrome-web-store/chrome-web-store-last-updated.service.js b/services/chrome-web-store/chrome-web-store-last-updated.service.js new file mode 100644 index 0000000000000..6bea2500e7caf --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-last-updated.service.js @@ -0,0 +1,41 @@ +import { age } from '../color-formatters.js' +import { formatDate } from '../text-formatters.js' +import { NotFound, pathParams } from '../index.js' +import BaseChromeWebStoreService from './chrome-web-store-base.js' + +export default class ChromeWebStoreLastUpdated extends BaseChromeWebStoreService { + static category = 'activity' + static route = { base: 'chrome-web-store/last-updated', pattern: ':storeId' } + + static openApi = { + '/chrome-web-store/last-updated/{storeId}': { + get: { + summary: 'Chrome Web Store Last Updated', + parameters: pathParams({ + name: 'storeId', + example: 'nccfelhkfpbnefflolffkclhenplhiab', + }), + }, + }, + } + + static defaultBadgeData = { + label: 'last updated', + } + + async handle({ storeId }) { + const chromeWebStore = await this.fetch({ storeId }) + const lastUpdated = chromeWebStore.lastUpdated() + + if (lastUpdated == null) { + throw new NotFound({ prettyMessage: 'not found' }) + } + + const lastUpdatedDate = Date.parse(lastUpdated) + + return { + message: formatDate(lastUpdatedDate), + color: age(lastUpdatedDate), + } + } +} diff --git a/services/chrome-web-store/chrome-web-store-last-updated.tester.js b/services/chrome-web-store/chrome-web-store-last-updated.tester.js new file mode 100644 index 0000000000000..3459b3702c28f --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-last-updated.tester.js @@ -0,0 +1,18 @@ +import { isFormattedDate } from '../test-validators.js' +import { createServiceTester } from '../tester.js' + +export const t = await createServiceTester() + +t.create('Last updated') + .get('/nccfelhkfpbnefflolffkclhenplhiab.json') + .expectBadge({ + label: 'last updated', + message: isFormattedDate, + }) + +t.create('Last updated (not found)') + .get('/invalid-name-of-addon.json') + .expectBadge({ + label: 'last updated', + message: 'not found', + }) diff --git a/services/chrome-web-store/chrome-web-store-size.service.js b/services/chrome-web-store/chrome-web-store-size.service.js new file mode 100644 index 0000000000000..12b11829e454a --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-size.service.js @@ -0,0 +1,35 @@ +import { NotFound, pathParams } from '../index.js' +import BaseChromeWebStoreService from './chrome-web-store-base.js' + +export default class ChromeWebStoreSize extends BaseChromeWebStoreService { + static category = 'size' + static route = { base: 'chrome-web-store/size', pattern: ':storeId' } + + static openApi = { + '/chrome-web-store/size/{storeId}': { + get: { + summary: 'Chrome Web Store Size', + parameters: pathParams({ + name: 'storeId', + example: 'nccfelhkfpbnefflolffkclhenplhiab', + }), + }, + }, + } + + static defaultBadgeData = { + label: 'extension size', + color: 'blue', + } + + async handle({ storeId }) { + const chromeWebStore = await this.fetch({ storeId }) + const size = chromeWebStore.size() + + if (size == null) { + throw new NotFound({ prettyMessage: 'not found' }) + } + + return { message: size } + } +} diff --git a/services/chrome-web-store/chrome-web-store-size.tester.js b/services/chrome-web-store/chrome-web-store-size.tester.js new file mode 100644 index 0000000000000..5eb2f9ae6d4cd --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-size.tester.js @@ -0,0 +1,13 @@ +import { createServiceTester } from '../tester.js' + +export const t = await createServiceTester() +const isFileSize = /^\d+(\.\d+)?(MiB|KiB)$/ + +t.create('Size').get('/nccfelhkfpbnefflolffkclhenplhiab.json').expectBadge({ + label: 'extension size', + message: isFileSize, +}) + +t.create('Size (not found)') + .get('/invalid-name-of-addon.json') + .expectBadge({ label: 'extension size', message: 'not found' })