Skip to content

Commit

Permalink
Fix api, add example building for api
Browse files Browse the repository at this point in the history
  • Loading branch information
maximtop committed Apr 1, 2024
1 parent 2a0bd1f commit 60c4064
Show file tree
Hide file tree
Showing 53 changed files with 1,006 additions and 493 deletions.
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'
7 changes: 0 additions & 7 deletions packages/adguard-api/.editorconfig

This file was deleted.

33 changes: 19 additions & 14 deletions packages/adguard-api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ module.exports = {
tsconfigRootDir: path.join(__dirname),
project: 'tsconfig.json',
},
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',
'jsdoc/no-undefined-types': 'off',
// TODO: enable and fix src
'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.

9 changes: 3 additions & 6 deletions packages/adguard-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"author": "Adguard Software Ltd.",
"license": "GPL-3.0-only",
"dependencies": {
"@adguard/assistant": "^4.3.70",
"@adguard/filters-downloader": "^1.1.23",
"@adguard/tswebextension": "^1.0.14",
"@adguard/assistant": "4.3.70",
"@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 60c4064

Please sign in to comment.