1- import { ClientMiddleware , createChannel , createClientFactory , ChannelCredentials } from 'nice-grpc' ;
1+ import { ClientMiddleware , createChannel , createClientFactory , ChannelCredentials , RawClient } from 'nice-grpc' ;
2+ import type { FromTsProtoServiceDefinition , TsProtoServiceDefinition } from 'nice-grpc/lib/service-definitions/ts-proto' ;
23import {
34 PermissionDefinition ,
45 SchemaDefinition ,
@@ -9,6 +10,22 @@ import {
910} from './generated/base/v1/service' ;
1011import { Config } from './config' ;
1112
13+ // Helper type to extract the client type from a service definition
14+ type ClientFromDefinition < T extends TsProtoServiceDefinition > = RawClient < FromTsProtoServiceDefinition < T > > ;
15+
16+ /**
17+ * Return type for the Permify gRPC client.
18+ * This explicit type ensures proper type preservation through export layers.
19+ */
20+ export type PermifyClient = {
21+ permission : ClientFromDefinition < typeof PermissionDefinition > ;
22+ schema : ClientFromDefinition < typeof SchemaDefinition > ;
23+ data : ClientFromDefinition < typeof DataDefinition > ;
24+ bundle : ClientFromDefinition < typeof BundleDefinition > ;
25+ tenancy : ClientFromDefinition < typeof TenancyDefinition > ;
26+ watch : ClientFromDefinition < typeof WatchDefinition > ;
27+ } ;
28+
1229/**
1330 * Create a new gRPC service client for Permify.
1431 * The client can be configured with multiple client interceptors. For authentication interceptors,
@@ -19,7 +36,7 @@ import { Config } from './config';
1936 *
2037 * @returns A new gRPC service client for the Permission API of Permify.
2138 */
22- export function newClient ( conf : Config , ...interceptors : ClientMiddleware [ ] ) {
39+ export function newClient ( conf : Config , ...interceptors : ClientMiddleware [ ] ) : PermifyClient {
2340 const channel = conf . insecure
2441 ? createChannel ( conf . endpoint , ChannelCredentials . createInsecure ( ) )
2542 : createChannel ( conf . endpoint , ChannelCredentials . createSsl ( conf . cert , conf . pk , conf . certChain ) ) ;
0 commit comments