Skip to content

Commit

Permalink
[release] @subql/[email protected], @subql/[email protected], @subq…
Browse files Browse the repository at this point in the history
…l/[email protected]

* [draft] eth provider

* [draft] eth provider

* clean up

* clean up

* chore: lint

* feat: use order retries

* feat: add ts support & change dev id

* feat: add timeout

* chore: reset test

* feat: release & workflow

* change log

---------

Co-authored-by: cyrbuzz <[email protected]>
  • Loading branch information
ianhe8x and HuberTRoy authored Nov 27, 2023
1 parent 86e48a5 commit 27f0b48
Show file tree
Hide file tree
Showing 53 changed files with 3,375 additions and 546 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/__mocks__/**
**/__graphql__/**
**/__hooks__/**
**/__hooks__/**
jest.config.ts
39 changes: 37 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": ["@typescript-eslint/eslint-plugin", "header"],
"plugins": ["@typescript-eslint", "header", "import", "sort-destructure-keys", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
],
"root": true,
"env": {
Expand All @@ -20,6 +23,38 @@
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
// "@typescript-eslint/explicit-member-accessibility": [
// "error",
// {
// "accessibility": "no-public"
// }
// ],
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"complexity": [
"error", 20],
"curly": [
"error", "multi-line"
],
"default-case": "error",
"eqeqeq": [
"error", "always"
],
"import/no-extraneous-dependencies": "off",
"import/order": [
"error",
{
"alphabetize": {
"order": "asc" /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */,
"caseInsensitive": true /* ignore case. Options: [true, false] */
}
}
],
"header/header": [2, "line", [
{
"pattern": " Copyright \\d{4}(-\\d{4})? SubQuery Pte Ltd authors & contributors",
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ jobs:
with:
paths: packages/network-config

- uses: marceloprado/has-changed-path@v1
id: changed-network-support
with:
paths: packages/network-support

- uses: marceloprado/has-changed-path@v1
id: changed-eth-provider
with:
paths: packages/eth-provider

- uses: marceloprado/has-changed-path@v1
id: changed-network-clients
with:
Expand Down Expand Up @@ -78,6 +88,20 @@ jobs:
package-path: packages/network-config
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Bump network-support & deploy
if: steps.changed-network-support.outputs.changed == 'true' || github.event.inputs.force-release
uses: ./.github/actions/create-prerelease
with:
package-path: packages/network-support
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Bump eth-provider & deploy
if: steps.changed-eth-provider.outputs.changed == 'true' || steps.changed-network-support == 'true' || github.event.inputs.force-release
uses: ./.github/actions/create-prerelease
with:
package-path: packages/eth-provider
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Bump network-query & deploy
if: steps.changed-network-query.outputs.changed == 'true' || github.event.inputs.force-release
uses: ./.github/actions/create-prerelease
Expand All @@ -100,7 +124,7 @@ jobs:
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Bump apollo-links & deploy
if: steps.changed-apollo-links.outputs.changed == 'true' || github.event.inputs.force-release
if: steps.changed-apollo-links.outputs.changed == 'true' || steps.changed-network-support == 'true' || github.event.inputs.force-release
uses: ./.github/actions/create-prerelease
with:
package-path: packages/apollo-links
Expand Down
29 changes: 27 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Release"
name: 'Release'
on:
push:
branches:
Expand Down Expand Up @@ -41,6 +41,16 @@ jobs:
with:
paths: packages/network-config

- uses: marceloprado/has-changed-path@v1
id: changed-network-support
with:
paths: packages/network-support

- uses: marceloprado/has-changed-path@v1
id: changed-eth-provider
with:
paths: packages/eth-provider

- uses: marceloprado/has-changed-path@v1
id: changed-network-clients
with:
Expand All @@ -55,7 +65,7 @@ jobs:
id: changed-react-hooks
with:
paths: packages/react-hooks

- uses: marceloprado/has-changed-path@v1
id: changed-apollo-links
with:
Expand Down Expand Up @@ -107,3 +117,18 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Publish network-support
if: steps.changed-network-support.outputs.changed == 'true'
uses: ./.github/actions/create-release
with:
package-path: packages/network-support
repo-token: ${{ secrets.GITHUB_TOKEN }}
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Publish eth-provider
if: steps.changed-eth-provider.outputs.changed == 'true'
uses: ./.github/actions/create-release
with:
package-path: packages/eth-provider
repo-token: ${{ secrets.GITHUB_TOKEN }}
npm-token: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions __mocks__/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

import mockAxios from 'jest-mock-axios';

export default mockAxios;
7 changes: 6 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export default {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},

moduleNameMapper: {
'^@subql/eth-provider$': '<rootDir>/packages/eth-provider/src/',
'^@subql/eth-provider/(.*)$': '<rootDir>/packages/eth-provider/src/$1',
'^@subql/network-support$': '<rootDir>/packages/network-support/src/',
'^@subql/network-support/(.*)$': '<rootDir>/packages/network-support/src/$1',
},
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: ['node_modules/(?!(@polkadot|@subql|@babel/runtime/helpers/esm)/)'],
};
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
"axios": "^0.27.2",
"ctix": "^1.5.4",
"dotenv": "^16.0.3",
"eslint": "^8.17.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-sort-destructure-keys": "^1.5.0",
"flag": "^5.0.1",
"graphql": "^16.5.0",
"graphql-language-service-server": "^2.8.9",
Expand All @@ -48,7 +51,9 @@
"packages/network-query",
"packages/apollo-links",
"packages/network-clients",
"packages/react-hooks"
"packages/react-hooks",
"packages/eth-provider",
"packages/network-support"
],
"lint-staged": {
"*.{ts,tsx}": [
Expand Down
5 changes: 4 additions & 1 deletion packages/apollo-links/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.3] - 2023-11-27

## [1.2.2] - 2023-11-13

## [1.1.0] - 2023-10-13
Expand Down Expand Up @@ -84,7 +86,8 @@ Breaking change for `dictHttpLink` and `deploymentHttpLink`, use `const { link }

- Add Authlink for Apollo client

[unreleased]: https://github.com/subquery/network-clients/compare/v1.2.2...HEAD
[unreleased]: https://github.com/subquery/network-clients/compare/v1.2.3...HEAD
[1.2.3]: https://github.com/subquery/network-clients/compare/v1.2.2...v1.2.3
[1.2.2]: https://github.com/subquery/network-clients/compare/v1.1.0...v1.2.2
[1.1.0]: https://github.com/subquery/network-clients/compare/v1.0.8...v1.1.0
[1.0.8]: https://github.com/subquery/network-clients/compare/v1.0.4...v1.0.8
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-links/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/apollo-links",
"version": "1.2.2",
"version": "1.2.3",
"description": "SubQuery Network - graphql links",
"main": "dist/index.js",
"author": "SubQuery Pte Limited",
Expand All @@ -10,8 +10,8 @@
},
"dependencies": {
"@metamask/eth-sig-util": "5.1.0",
"@subql/network-support": "workspace:*",
"apollo-link-error": "^1.1.13",
"axios": "^0.27.2",
"buffer": "^6.0.3",
"cross-fetch": "^4.0.0",
"ethers": "^5.6.8",
Expand Down
17 changes: 2 additions & 15 deletions packages/apollo-links/src/auth/authHelper.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import jwt_decode from 'jwt-decode';
import buffer from 'buffer';
import { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import { POST } from '@subql/network-support';

import { AuthMessage, buildTypedMessage, createAuthRequestBody } from './eip712';
import { POST } from '../utils/query';

const Buffer = buffer.Buffer;

export function isTokenExpired(token: string): boolean {
if (!token) return true;

try {
const { exp } = jwt_decode(token) as { exp: number };
const currentDate = new Date().getTime();
return exp < currentDate;
} catch {
return true;
}
}

export function signMessage(msg: AuthMessage, sk: string, chainId: number): string {
if (!sk) return '';

Expand Down
31 changes: 23 additions & 8 deletions packages/apollo-links/src/authHttpLink.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ApolloLink, from } from '@apollo/client/core';

import {
IStore,
OrderManager,
ResponseFormat,
RunnerSelector,
setFetchTimeout,
} from '@subql/network-support';
import {
ClusterAuthLink,
createRetryLink,
creatErrorLink,
DynamicHttpLink,
FallbackLink,
Options,
ResponseLink,
creatErrorLink,
createRetryLink,
} from './core';
import { ProjectType } from './types';
import { Logger, silentLogger } from './utils/logger';
import { OrderManager } from './core/orderManager';
import { IStore } from './utils/store';

interface BaseAuthOptions {
authUrl: string; // auth service url
httpOptions: Options['httpOptions']; // http options for init `HttpLink`
logger?: Logger; // logger for `AuthLink`
fallbackServiceUrl?: string; // fall back service url for `AuthLink`
scoreStore?: IStore; // pass store in, so it doesn't get lost between page refresh
selector?: RunnerSelector;
maxRetries?: number;
useImmediateFallbackOnError?: boolean;
timeout?: number;
}

interface DictAuthOptions extends BaseAuthOptions {
export interface DictAuthOptions extends BaseAuthOptions {
chainId: string; // chain id for the requested dictionary
}

interface DeploymentAuthOptions extends BaseAuthOptions {
export interface DeploymentAuthOptions extends BaseAuthOptions {
deploymentId: string; // deployment id
}

interface AuthOptions extends DeploymentAuthOptions {
export interface AuthOptions extends DeploymentAuthOptions {
projectType: ProjectType; // order type
}

Expand All @@ -60,17 +67,25 @@ function authHttpLink(options: AuthOptions): AuthHttpLink {
fallbackServiceUrl,
authUrl,
projectType,
scoreStore,
maxRetries,
useImmediateFallbackOnError = false,
logger: _logger,
timeout = 60000,
selector,
} = options;
setFetchTimeout(timeout);

const logger = _logger ?? silentLogger();
const orderManager = new OrderManager({
authUrl,
projectId: deploymentId,
projectType,
logger,
scoreStore,
responseFormat: ResponseFormat.Inline,
selector,
timeout,
});

const retryLink = createRetryLink({ orderManager, logger, maxRetries });
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-links/src/core/authLink.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ApolloLink, FetchResult, NextLink, Observable, Operation } from '@apollo/client/core';
import { isTokenExpired } from '@subql/network-support';
import { Subscription } from 'zen-observable-ts';

import { isTokenExpired, requestAuthToken } from '../auth/authHelper';
import { Message } from '../auth/eip712';
import { Message, requestAuthToken } from '../auth';
import { Logger } from '../utils/logger';

interface AuthOptions extends Message {
Expand Down
Loading

0 comments on commit 27f0b48

Please sign in to comment.