@subql/apollo-links
Advanced tools
Comparing version 0.5.2 to 0.5.3
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
@@ -9,18 +10,28 @@ | ||
## [0.5.3] - 2023-07-13 | ||
## [0.5.2] - 2023-06-19 | ||
### Changed | ||
- upgrade @metamask/eth-sig-util to ^5.1.0 | ||
## [0.5.1] - 2023-06-15 | ||
### Changed | ||
- Improve retry logic & logs (#129) | ||
### Added | ||
- More unit tests for retry logic and fallover | ||
## [0.5.0] - 2023-06-14 | ||
### Fixed | ||
- fix the apollo/client import to /core to avoid react dep (#125) | ||
### Changed | ||
- separate the link create function for dict & project (#124) | ||
@@ -30,17 +41,25 @@ - rename projectHttpLink to deploymentHttpLink (#126) | ||
## [0.4.0] - 2023-06-13 | ||
### Added | ||
- Feat/auth link routing (#122) | ||
## [0.3.4] - 2023-06-13 | ||
### Added | ||
- Get networkChainId from authURl (#108) | ||
### Fixed | ||
- Fix runtime error catch for authLink (#120) | ||
## [0.2.1] - 2023-06-13 | ||
### Added | ||
- Add Authlink for Apollo client | ||
[Unreleased]: https://github.com/subquery/network-clients/compare/v0.5.2...HEAD | ||
[unreleased]: https://github.com/subquery/network-clients/compare/v0.5.3...HEAD | ||
[0.5.3]: https://github.com/subquery/network-clients/compare/v0.5.2...v0.5.3 | ||
[0.5.2]: https://github.com/subquery/network-clients/compare/v0.5.1...v0.5.2 | ||
@@ -47,0 +66,0 @@ [0.5.1]: https://github.com/subquery/network-clients/compare/v0.5.0...v0.5.1 |
import { ApolloLink, HttpOptions } from '@apollo/client/core'; | ||
import { Logger } from './logger'; | ||
import { Logger } from './utils/logger'; | ||
interface DictAuthOptions extends BaseAuthOptions { | ||
@@ -4,0 +4,0 @@ chainId: string; |
@@ -10,28 +10,35 @@ "use strict"; | ||
const core_1 = require("@apollo/client/core"); | ||
const auth_link_1 = require("./auth-link"); | ||
const dynamicHttpLink_1 = require("./dynamicHttpLink"); | ||
const agreementManager_1 = __importDefault(require("./agreementManager")); | ||
const errorLink_1 = require("./errorLink"); | ||
const retryLink_1 = require("./retryLink"); | ||
const logger_1 = require("./logger"); | ||
const fallbackLink_1 = require("./fallbackLink"); | ||
const orderManager_1 = __importDefault(require("./utils/orderManager")); | ||
const logger_1 = require("./utils/logger"); | ||
const types_1 = require("./types"); | ||
const core_2 = require("./core"); | ||
function dictHttpLink(options) { | ||
const { chainId } = options; | ||
return deploymentHttpLink(Object.assign(Object.assign({}, options), { deploymentId: chainId })); | ||
return authHttpLink(Object.assign(Object.assign({}, options), { deploymentId: chainId, projectType: types_1.ProjectType.dictionary })); | ||
} | ||
exports.dictHttpLink = dictHttpLink; | ||
function deploymentHttpLink(options) { | ||
const { deploymentId, httpOptions, fallbackServiceUrl, authUrl, logger: _logger } = options; | ||
return authHttpLink(Object.assign(Object.assign({}, options), { projectType: types_1.ProjectType.deployment })); | ||
} | ||
exports.deploymentHttpLink = deploymentHttpLink; | ||
function authHttpLink(options) { | ||
const { deploymentId, httpOptions, fallbackServiceUrl, authUrl, logger: _logger, projectType, } = options; | ||
const logger = _logger !== null && _logger !== void 0 ? _logger : (0, logger_1.silentLogger)(); | ||
const agreementManager = new agreementManager_1.default({ authUrl, projectId: deploymentId, logger }); | ||
const retryLink = (0, retryLink_1.createRetryLink)(logger); | ||
const fallbackLink = new fallbackLink_1.FallbackLink(fallbackServiceUrl, logger); | ||
const httpLink = new dynamicHttpLink_1.DynamicHttpLink({ httpOptions, logger }); | ||
const errorLink = (0, errorLink_1.creatErrorLink)({ logger, fallbackLink, httpLink }); | ||
const authLink = new auth_link_1.ClusterAuthLink({ | ||
const orderMananger = new orderManager_1.default({ | ||
authUrl, | ||
projectId: deploymentId, | ||
logger, | ||
agreementManager, | ||
projectType, | ||
}); | ||
const retryLink = (0, core_2.createRetryLink)(logger); | ||
const fallbackLink = new core_2.FallbackLink(fallbackServiceUrl, logger); | ||
const httpLink = new core_2.DynamicHttpLink({ httpOptions, logger }); | ||
const responseLink = new core_2.ResponseLink({ logger, authUrl }); | ||
const errorLink = (0, core_2.creatErrorLink)({ logger, fallbackLink, httpLink }); | ||
const authLink = new core_2.ClusterAuthLink({ | ||
authUrl, | ||
projectId: deploymentId, | ||
logger, | ||
orderMananger, | ||
}); | ||
// 1. errorLink: This link helps in handling and logging any GraphQL or network errors that may occur down the chain. | ||
@@ -42,5 +49,4 @@ // Placing it at the beginning ensures that it catches any errors that may occur in any of the other links. | ||
// 4. httpLink: This should always be at the end of the link chain. This link is responsible for sending the request to the server. | ||
return (0, core_1.from)([errorLink, retryLink, authLink, fallbackLink, httpLink]); | ||
return (0, core_1.from)([errorLink, retryLink, authLink, fallbackLink, responseLink, httpLink]); | ||
} | ||
exports.deploymentHttpLink = deploymentHttpLink; | ||
//# sourceMappingURL=authHttpLink.js.map |
export * from './authHttpLink'; | ||
export * from './auth-link'; | ||
export * from './auth'; | ||
export * from './core'; |
@@ -20,3 +20,4 @@ "use strict"; | ||
__exportStar(require("./authHttpLink"), exports); | ||
__exportStar(require("./auth-link"), exports); | ||
__exportStar(require("./auth"), exports); | ||
__exportStar(require("./core"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,9 @@ | ||
export declare enum ProjectType { | ||
dictionary = "dictionary", | ||
deployment = "deployment" | ||
} | ||
export declare enum OrderType { | ||
agreement = "agreement", | ||
flexPlan = "flexPlan" | ||
} | ||
export declare type Agreement = { | ||
@@ -7,1 +15,16 @@ id: string; | ||
}; | ||
export declare type Plan = { | ||
id: string; | ||
indexer: string; | ||
url: string; | ||
}; | ||
export declare type ChannelState = { | ||
channelId: string; | ||
indexer: string; | ||
consumer: string; | ||
spent: string; | ||
remote: string; | ||
isFinal: boolean; | ||
indexerSign: string; | ||
consumerSign: string; | ||
}; |
@@ -5,2 +5,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OrderType = exports.ProjectType = void 0; | ||
var ProjectType; | ||
(function (ProjectType) { | ||
ProjectType["dictionary"] = "dictionary"; | ||
ProjectType["deployment"] = "deployment"; | ||
})(ProjectType = exports.ProjectType || (exports.ProjectType = {})); | ||
var OrderType; | ||
(function (OrderType) { | ||
OrderType["agreement"] = "agreement"; | ||
OrderType["flexPlan"] = "flexPlan"; | ||
})(OrderType = exports.OrderType || (exports.OrderType = {})); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@subql/apollo-links", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "SubQuery Network - graphql links", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -6,9 +6,13 @@ // Copyright 2020-2022 SubQuery Pte Ltd authors & contributors | ||
import { ClusterAuthLink } from './auth-link'; | ||
import { DynamicHttpLink } from './dynamicHttpLink'; | ||
import AgreementManager from './agreementManager'; | ||
import { creatErrorLink } from './errorLink'; | ||
import { createRetryLink } from './retryLink'; | ||
import { Logger, silentLogger } from './logger'; | ||
import { FallbackLink } from './fallbackLink'; | ||
import OrderMananger from './utils/orderManager'; | ||
import { Logger, silentLogger } from './utils/logger'; | ||
import { ProjectType } from './types'; | ||
import { | ||
createRetryLink, | ||
FallbackLink, | ||
DynamicHttpLink, | ||
ResponseLink, | ||
creatErrorLink, | ||
ClusterAuthLink, | ||
} from './core'; | ||
@@ -23,2 +27,6 @@ interface DictAuthOptions extends BaseAuthOptions { | ||
interface AuthOptions extends DeploymentAuthOptions { | ||
projectType: ProjectType; // order type | ||
} | ||
interface BaseAuthOptions { | ||
@@ -33,10 +41,26 @@ authUrl: string; // auth service url | ||
const { chainId } = options; | ||
return deploymentHttpLink({ ...options, deploymentId: chainId }); | ||
return authHttpLink({ ...options, deploymentId: chainId, projectType: ProjectType.dictionary }); | ||
} | ||
export function deploymentHttpLink(options: DeploymentAuthOptions): ApolloLink { | ||
const { deploymentId, httpOptions, fallbackServiceUrl, authUrl, logger: _logger } = options; | ||
return authHttpLink({ ...options, projectType: ProjectType.deployment }); | ||
} | ||
function authHttpLink(options: AuthOptions): ApolloLink { | ||
const { | ||
deploymentId, | ||
httpOptions, | ||
fallbackServiceUrl, | ||
authUrl, | ||
logger: _logger, | ||
projectType, | ||
} = options; | ||
const logger = _logger ?? silentLogger(); | ||
const agreementManager = new AgreementManager({ authUrl, projectId: deploymentId, logger }); | ||
const orderMananger = new OrderMananger({ | ||
authUrl, | ||
projectId: deploymentId, | ||
logger, | ||
projectType, | ||
}); | ||
@@ -46,2 +70,3 @@ const retryLink = createRetryLink(logger); | ||
const httpLink = new DynamicHttpLink({ httpOptions, logger }); | ||
const responseLink = new ResponseLink({ logger, authUrl }); | ||
const errorLink = creatErrorLink({ logger, fallbackLink, httpLink }); | ||
@@ -52,3 +77,3 @@ const authLink = new ClusterAuthLink({ | ||
logger, | ||
agreementManager, | ||
orderMananger, | ||
}); | ||
@@ -61,3 +86,3 @@ | ||
// 4. httpLink: This should always be at the end of the link chain. This link is responsible for sending the request to the server. | ||
return from([errorLink, retryLink, authLink, fallbackLink, httpLink]); | ||
return from([errorLink, retryLink, authLink, fallbackLink, responseLink, httpLink]); | ||
} |
@@ -5,2 +5,3 @@ // Copyright 2020-2022 SubQuery Pte Ltd authors & contributors | ||
export * from './authHttpLink'; | ||
export * from './auth-link'; | ||
export * from './auth'; | ||
export * from './core'; |
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
export enum ProjectType { | ||
dictionary = 'dictionary', | ||
deployment = 'deployment', | ||
} | ||
export enum OrderType { | ||
agreement = 'agreement', | ||
flexPlan = 'flexPlan', | ||
} | ||
export type Agreement = { | ||
id: string; | ||
id: string; // agreement id | ||
indexer: string; | ||
url: string; | ||
token: string; | ||
} | ||
}; | ||
export type Plan = { | ||
id: string; // state channel id | ||
indexer: string; | ||
url: string; | ||
}; | ||
export type ChannelState = { | ||
channelId: string; | ||
indexer: string; | ||
consumer: string; | ||
spent: string; | ||
remote: string; | ||
isFinal: boolean; | ||
indexerSign: string; | ||
consumerSign: string; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149807
73
1592
1