Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'grpc-caller' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
let certPathParts = this.certPath.split(path.sep)
if (certPathParts[0] === '~') {
certPathParts[0] = os.homedir()
this.cert = readFileSync(path.join(...certPathParts))
} else {
this.cert = readFileSync(this.certPath)
}
const channelCredentials = grpc.credentials.createSsl(this.cert)
const callCredentials = basicAuth.generateBasicAuthCredentials(this.username, this.password)
this.credentials = grpc.credentials.combineChannelCredentials(channelCredentials, callCredentials)
}
const adminServiceClient = new this.proto.broker.rpc.AdminService(this.address, this.credentials)
this.adminService = caller.wrap(adminServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderServiceClient = new this.proto.broker.rpc.OrderService(this.address, this.credentials)
this.orderService = caller.wrap(orderServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderBookServiceClient = new this.proto.broker.rpc.OrderBookService(this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const walletServiceClient = new this.proto.broker.rpc.WalletService(this.address, this.credentials)
this.walletService = caller.wrap(walletServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
}
}
export async function deleteGraphUser(tenant: string, email: string) {
const user = caller(
`${process.env.GRAPH_HOST || 'graph'}:443`,
path.resolve(__dirname, 'graph.proto'),
'UserService',
);
await user.Delete({tenant, id: email}).catch(err => console.error(err));
}
export async function triggerActionsAlert(payload: Payload) {
logger.info('sending payload: %s', payload);
const actionsAlertService = caller(
`${process.env.GRAPH_HOST || 'graph'}:443`,
path.resolve(__dirname, 'graph.proto'),
'ActionsAlertService',
);
await actionsAlertService.Trigger(payload).catch(err => console.error(err));
}
export async function createGraphUser(
tenant: string,
email: string,
isOwner: boolean,
) {
const user = caller(
`${process.env.GRAPH_HOST || 'graph'}:443`,
path.resolve(__dirname, 'graph.proto'),
'UserService',
);
await user
.Create({tenant, id: email, isOwner})
.catch(err => console.error(err));
}
const callCredentials = basicAuth.generateBasicAuthCredentials(this.username, this.password)
this.credentials = grpc.credentials.combineChannelCredentials(channelCredentials, callCredentials)
}
const adminServiceClient = new this.proto.broker.rpc.AdminService(this.address, this.credentials)
this.adminService = caller.wrap(adminServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderServiceClient = new this.proto.broker.rpc.OrderService(this.address, this.credentials)
this.orderService = caller.wrap(orderServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderBookServiceClient = new this.proto.broker.rpc.OrderBookService(this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const walletServiceClient = new this.proto.broker.rpc.WalletService(this.address, this.credentials)
this.walletService = caller.wrap(walletServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
}
}
if (!PRODUCTION) {
logger.info('Using local certs for relayer client', { production: PRODUCTION })
channelCredentials = credentials.createSsl(readFileSync(certPath))
}
this.credentials = channelCredentials
const options = { interceptors: [grpcDeadlineInterceptor] }
const orderServiceClient = new this.proto.OrderService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderService = caller.wrap(orderServiceClient, {}, options)
const makerServiceClient = new this.proto.MakerService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.makerService = caller.wrap(makerServiceClient, {}, options)
const takerServiceClient = new this.proto.TakerService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.takerService = caller.wrap(takerServiceClient, {}, options)
const orderBookServiceClient = new this.proto.OrderBookService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, options)
const paymentChannelNetworkServiceClient =
new this.proto.PaymentChannelNetworkService(
this.address, this.credentials)
this.paymentChannelNetworkService =
caller.wrap(paymentChannelNetworkServiceClient, {}, options)
const adminServiceClient = new this.proto.AdminService(
this.cert = readFileSync(path.join(...certPathParts))
} else {
this.cert = readFileSync(this.certPath)
}
const channelCredentials = grpc.credentials.createSsl(this.cert)
const callCredentials = basicAuth.generateBasicAuthCredentials(this.username, this.password)
this.credentials = grpc.credentials.combineChannelCredentials(channelCredentials, callCredentials)
}
const adminServiceClient = new this.proto.broker.rpc.AdminService(this.address, this.credentials)
this.adminService = caller.wrap(adminServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderServiceClient = new this.proto.broker.rpc.OrderService(this.address, this.credentials)
this.orderService = caller.wrap(orderServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderBookServiceClient = new this.proto.broker.rpc.OrderBookService(this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const walletServiceClient = new this.proto.broker.rpc.WalletService(this.address, this.credentials)
this.walletService = caller.wrap(walletServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
}
}
this.proto = loadProto(path.resolve(RELAYER_PROTO_PATH))
this.identity = Identity.load(privKeyPath, pubKeyPath)
let channelCredentials = credentials.createSsl()
if (!PRODUCTION) {
logger.info('Using local certs for relayer client', { production: PRODUCTION })
channelCredentials = credentials.createSsl(readFileSync(certPath))
}
this.credentials = channelCredentials
const options = { interceptors: [grpcDeadlineInterceptor] }
const orderServiceClient = new this.proto.OrderService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderService = caller.wrap(orderServiceClient, {}, options)
const makerServiceClient = new this.proto.MakerService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.makerService = caller.wrap(makerServiceClient, {}, options)
const takerServiceClient = new this.proto.TakerService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.takerService = caller.wrap(takerServiceClient, {}, options)
const orderBookServiceClient = new this.proto.OrderBookService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, options)
const paymentChannelNetworkServiceClient =
new this.proto.PaymentChannelNetworkService(
this.address, this.credentials)
}
this.credentials = channelCredentials
const options = { interceptors: [grpcDeadlineInterceptor] }
const orderServiceClient = new this.proto.OrderService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderService = caller.wrap(orderServiceClient, {}, options)
const makerServiceClient = new this.proto.MakerService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.makerService = caller.wrap(makerServiceClient, {}, options)
const takerServiceClient = new this.proto.TakerService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.takerService = caller.wrap(takerServiceClient, {}, options)
const orderBookServiceClient = new this.proto.OrderBookService(
this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, options)
const paymentChannelNetworkServiceClient =
new this.proto.PaymentChannelNetworkService(
this.address, this.credentials)
this.paymentChannelNetworkService =
caller.wrap(paymentChannelNetworkServiceClient, {}, options)
const adminServiceClient = new this.proto.AdminService(
this.address, this.credentials)
this.adminService = caller.wrap(adminServiceClient, {}, options)
}
}
const channelCredentials = grpc.credentials.createSsl(this.cert)
const callCredentials = basicAuth.generateBasicAuthCredentials(this.username, this.password)
this.credentials = grpc.credentials.combineChannelCredentials(channelCredentials, callCredentials)
}
const adminServiceClient = new this.proto.broker.rpc.AdminService(this.address, this.credentials)
this.adminService = caller.wrap(adminServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderServiceClient = new this.proto.broker.rpc.OrderService(this.address, this.credentials)
this.orderService = caller.wrap(orderServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const orderBookServiceClient = new this.proto.broker.rpc.OrderBookService(this.address, this.credentials, GRPC_STREAM_OPTIONS)
this.orderBookService = caller.wrap(orderBookServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
const walletServiceClient = new this.proto.broker.rpc.WalletService(this.address, this.credentials)
this.walletService = caller.wrap(walletServiceClient, {}, { interceptors: [grpcDeadlineInterceptor] })
}
}