@vivse/frontend-library
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -0,5 +1,6 @@ | ||
import { AuthToken } from "./auth-token"; | ||
export declare const createConnectionLink: ({ httpEndpoint, wsEndpoint, getAuthToken, }: { | ||
httpEndpoint: string; | ||
wsEndpoint: string; | ||
getAuthToken: () => Promise<string | undefined | null> | string | undefined | null; | ||
wsEndpoint?: string | undefined; | ||
getAuthToken: () => Promise<AuthToken> | AuthToken; | ||
}) => import("@apollo/client").ApolloLink; |
@@ -18,2 +18,3 @@ "use strict"; | ||
const graphql_ws_1 = require("graphql-ws"); | ||
const defs_1 = require("@vivse/shared-library/defs"); | ||
const createConnectionLink = ({ httpEndpoint, wsEndpoint, getAuthToken, }) => { | ||
@@ -23,18 +24,28 @@ const httpLink = (0, client_1.createHttpLink)({ | ||
}); | ||
const wsLink = new subscriptions_1.GraphQLWsLink((0, graphql_ws_1.createClient)({ | ||
url: wsEndpoint, | ||
})); | ||
const splitLink = (0, client_1.split)(({ query }) => { | ||
const definition = (0, utilities_1.getMainDefinition)(query); | ||
return (definition.kind === "OperationDefinition" && | ||
definition.operation === "subscription"); | ||
}, wsLink, httpLink); | ||
const wsLink = wsEndpoint && | ||
new subscriptions_1.GraphQLWsLink((0, graphql_ws_1.createClient)({ | ||
url: wsEndpoint, | ||
})); | ||
const connectionLink = wsLink | ||
? (0, client_1.split)(({ query }) => { | ||
const definition = (0, utilities_1.getMainDefinition)(query); | ||
return (definition.kind === "OperationDefinition" && | ||
definition.operation === "subscription"); | ||
}, wsLink, httpLink) | ||
: httpLink; | ||
const authLink = (0, context_1.setContext)((_, { headers }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const token = yield getAuthToken(); | ||
const authToken = yield getAuthToken(); | ||
if (!authToken) | ||
return {}; | ||
const { token, type } = authToken; | ||
return { | ||
headers: Object.assign(Object.assign({}, headers), { authorization: token ? `Bearer ${token}` : "" }), | ||
headers: Object.assign(Object.assign({}, headers), { [type === "bearer" ? "Authorization" : defs_1.VERIFY_TOKEN_HEADER]: token | ||
? type === "bearer" | ||
? `Bearer ${token}` | ||
: token | ||
: "" }), | ||
}; | ||
})); | ||
return authLink.concat(splitLink); | ||
return authLink.concat(connectionLink); | ||
}; | ||
exports.createConnectionLink = createConnectionLink; |
{ | ||
"name": "@vivse/frontend-library", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Library shared between react projects", | ||
@@ -13,2 +13,3 @@ "main": "dist/index.js", | ||
"@types/ramda": "^0.28.11", | ||
"@vivse/shared-library": "1.1.4", | ||
"graphql-ws": "^5.8.2", | ||
@@ -28,2 +29,3 @@ "husky": "8.0.1", | ||
"@apollo/client": "^3.6.6", | ||
"@vivse/shared-library": "*", | ||
"graphql-ws": "^5.8.2" | ||
@@ -30,0 +32,0 @@ }, |
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
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
7756
13
146
4
9