Skip to content

Commit

Permalink
Fix adguard-api, add example building for api
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from fix/api to master

Squashed commit of the following:

commit 871a2f2
Author: Maxim Topciu <[email protected]>
Date:   Tue Apr 2 11:34:58 2024 +0300

    use types where possible

commit dcfe912
Author: Maxim Topciu <[email protected]>
Date:   Tue Apr 2 11:31:15 2024 +0300

    update changelog

commit c49026f
Author: Maxim Topciu <[email protected]>
Date:   Tue Apr 2 11:29:25 2024 +0300

    extract zip filename to the constant

commit 4351821
Author: Maxim Topciu <[email protected]>
Date:   Mon Apr 1 19:34:38 2024 +0300

    update pnpm file

commit 7a0cc4d
Author: Maxim Topciu <[email protected]>
Date:   Mon Apr 1 19:29:58 2024 +0300

    revert some configs

commit 14df4d9
Author: Maxim Topciu <[email protected]>
Date:   Mon Apr 1 19:20:11 2024 +0300

    Build sample extension with adguard api

commit 60c4064
Author: Maxim Topciu <[email protected]>
Date:   Mon Apr 1 19:12:55 2024 +0300

    Fix api, add example building for api
  • Loading branch information
maximtop committed Apr 2, 2024
1 parent 2a0bd1f commit 12a40fe
Show file tree
Hide file tree
Showing 54 changed files with 1,020 additions and 466 deletions.
9 changes: 9 additions & 0 deletions bamboo-specs/adguard-api-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ Build:
# Install dependencies
pnpm install
# Build api
npx lerna run build --scope @adguard/api --include-dependencies
# Build extension with api, for manual testing
npx lerna run build --scope adguard-api-example --include-dependencies
cd packages/adguard-api
pnpm pack && mv adguard-api-*.tgz adguard-api.tgz
- inject-variables:
Expand Down Expand Up @@ -80,6 +84,11 @@ Build:
pattern: adguard-api.tgz
shared: true
required: true
- name: extension.zip
location: packages/examples/adguard-api/build
pattern: extension.zip
shared: true
required: true
requirements:
- adg-docker: 'true'

Expand Down
94 changes: 94 additions & 0 deletions bamboo-specs/adguard-api-example-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
version: 2
plan:
project-key: AJL
key: AGAPIEXTEST
name: adguard-api-example - tests
variables:
dockerContainer: adguard/node-ssh:18.19--0

stages:
- Test:
manual: false
final: false
jobs:
- Test

Test:
key: TEST
docker:
image: "${bamboo.dockerContainer}"
volumes:
${system.PNPM_DIR}: "${bamboo.cachePnpm}"
tasks:
- checkout:
force-clean-build: 'true'
- script:
interpreter: SHELL
scripts:
- |-
set -e
set -x
# Fix mixed logs
exec 2>&1
ls -alt
# Set cache directory
pnpm config set store-dir ${bamboo.cachePnpm}
# Install deps
pnpm install
# Lint
pnpm --filter adguard-api-example lint
# Build
npx lerna run build --scope adguard-api-example --include-dependencies
artifacts:
- name: extension.zip
location: packages/examples/adguard-api/build
pattern: extension.zip
shared: true
required: false
final-tasks:
- script:
interpreter: SHELL
scripts:
- |-
set -x
set -e
# Fix mixed logs
exec 2>&1
ls -la
echo "Size before cleanup:" && du -h | tail -n 1
pnpm clean
echo "Size after cleanup:" && du -h | tail -n 1
requirements:
- adg-docker: 'true'

branches:
create: for-pull-request
delete:
after-deleted-days: '1'
after-inactive-days: '5'
link-to-jira: 'true'

notifications:
- events:
- plan-status-changed
recipients:
- webhook:
name: Build webhook
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo

labels: [ ]

other:
concurrent-build-plugin: system-default
3 changes: 3 additions & 0 deletions bamboo-specs/bamboo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@

---
!include 'logger-test.yaml'

---
!include 'adguard-api-example-tests.yaml'
2 changes: 1 addition & 1 deletion packages/adguard-api/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ insert_final_newline = true
end_of_line = lf
indent_style = space
indent_size = 4
max_line_length = 120
max_line_length = 120
22 changes: 19 additions & 3 deletions packages/adguard-api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ module.exports = {
env: {
browser: true,
},
plugins: [
'import',
'import-newlines',
],
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:jsdoc/recommended',
'plugin:prettier/recommended',
'plugin:@typescript-eslint/eslint-recommended',
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'error',
indent: 'off',
'@typescript-eslint/indent': ['error', 4],
'no-bitwise': 'off',
'no-new': 'off',
'max-len': ['error', { code: 120, ignoreUrls: true }],
'import-newlines/enforce': ['error', 3, 120],
'import/prefer-default-export': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off',
Expand All @@ -26,5 +35,12 @@ module.exports = {
'jsdoc/tag-lines': 'off',
'jsdoc/require-throws': 'error',
'jsdoc/require-file-overview': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-continue': 'off',
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
'no-constant-condition': ['error', { checkLoops: false }],
'@typescript-eslint/interface-name-prefix': 'off',
'arrow-body-style': 'off',
},
};
};
3 changes: 0 additions & 3 deletions packages/adguard-api/.prettierrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions packages/adguard-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.4] - 2024-04-02

### Changed
- Update `@adguard/tswebextension` to `^1.0.22`.
- Update `@adguard/filters-downloader` to `^2.2.0`.

## [2.1.3] - 2024-02-15

### Changed
Expand Down
9 changes: 3 additions & 6 deletions packages/adguard-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adguard/api",
"version": "2.1.3",
"version": "2.1.4",
"description": "This is a TypeScript library that implements AdGuard's extension API",
"main": "dist/adguard-api.js",
"files": [
Expand Down Expand Up @@ -36,8 +36,8 @@
"license": "GPL-3.0-only",
"dependencies": {
"@adguard/assistant": "^4.3.70",
"@adguard/filters-downloader": "^1.1.23",
"@adguard/tswebextension": "^1.0.14",
"@adguard/filters-downloader": "^2.2.0",
"@adguard/tswebextension": "^1.0.22",
"webextension-polyfill": "0.10.0",
"zod": "3.22.4"
},
Expand All @@ -55,11 +55,8 @@
"eslint": "8.54.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.1.0",
"rollup": "^4.6.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
Expand Down
38 changes: 18 additions & 20 deletions packages/adguard-api/src/background/filters/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with Adguard API. If not, see <http://www.gnu.org/licenses/>.
*/
import { Network } from "../network";
import { Storage } from "../storage";
import { MetadataApi } from "./metadata";
import { VersionsApi } from "./versions";
import { FilterRulesApi } from "./rules";
import { BrowserUtils, I18n } from "../utils";
import { FilterMetadata } from "../schemas";
import { notifier, NotifierEventType } from "../notifier";
import { Logger } from "../logger";
import { Network } from '../network';
import { Storage } from '../storage';
import { MetadataApi } from './metadata';
import { VersionsApi } from './versions';
import { FilterRulesApi } from './rules';
import { BrowserUtils, I18n } from '../utils';
import { FilterMetadata } from '../schemas';
import { notifier, NotifierEventType } from '../notifier';
import { Logger } from '../logger';

/**
* Filter Api provides methods for managing filters data
Expand Down Expand Up @@ -72,13 +72,11 @@ export class FiltersApi {
* @param filterIds - list of filter ids
* @returns filters data for {@link TsWebExtension} configuration
*/
public async getFilters(filterIds: number[]): Promise<
{
content: string;
filterId: number;
trusted: boolean;
}[]
> {
public async getFilters(filterIds: number[]): Promise<{
content: string;
filterId: number;
trusted: boolean;
}[]> {
const tasks = filterIds.map((id) => this.getFilter(id));

return Promise.all(tasks);
Expand Down Expand Up @@ -106,7 +104,7 @@ export class FiltersApi {

return {
filterId,
content: (rules || []).join("\n"),
content: (rules || []).join('\n'),
trusted: true,
};
}
Expand All @@ -123,7 +121,7 @@ export class FiltersApi {
* @returns List of outdated filters ids.
*/
public async updateFilters(): Promise<number[]> {
this.logger.info("Update filters");
this.logger.info('Update filters');
/**
* Reload filters metadata from backend for correct
* version matching on update check.
Expand Down Expand Up @@ -171,8 +169,8 @@ export class FiltersApi {
const promises = await Promise.allSettled(tasks);
// Handles errors
promises.forEach((promise) => {
if (promise.status === "rejected") {
this.logger.error("Cannot remove obsoleted filter from storage due to: ", promise.reason);
if (promise.status === 'rejected') {
this.logger.error('Cannot remove obsoleted filter from storage due to: ', promise.reason);
}
});

Expand Down
6 changes: 3 additions & 3 deletions packages/adguard-api/src/background/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// Entry point for filter management modules

// Filters data management API
export { FiltersApi } from "./api";
export { FiltersApi } from './api';

// Service for scheduling filters rules updates
export { FiltersUpdateService } from "./update";
export { FiltersUpdateService } from './update';

// Service for auto-enabling language filters
export { LocaleDetectService } from "./locale-detect";
export { LocaleDetectService } from './locale-detect';
Loading

0 comments on commit 12a40fe

Please sign in to comment.