Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@permify/permify-node",
"version": "1.1.2",
"version": "1.1.3",
"description": "Permify Node Client",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
21 changes: 19 additions & 2 deletions src/grpc/clients.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ClientMiddleware, createChannel, createClientFactory, ChannelCredentials } from 'nice-grpc';
import { ClientMiddleware, createChannel, createClientFactory, ChannelCredentials, RawClient } from 'nice-grpc';
import type { FromTsProtoServiceDefinition, TsProtoServiceDefinition } from 'nice-grpc/lib/service-definitions/ts-proto';
import {
PermissionDefinition,
SchemaDefinition,
Expand All @@ -9,6 +10,22 @@ import {
} from './generated/base/v1/service';
import { Config } from './config';

// Helper type to extract the client type from a service definition
type ClientFromDefinition<T extends TsProtoServiceDefinition> = RawClient<FromTsProtoServiceDefinition<T>>;

/**
* Return type for the Permify gRPC client.
* This explicit type ensures proper type preservation through export layers.
*/
export type PermifyClient = {
permission: ClientFromDefinition<typeof PermissionDefinition>;
schema: ClientFromDefinition<typeof SchemaDefinition>;
data: ClientFromDefinition<typeof DataDefinition>;
bundle: ClientFromDefinition<typeof BundleDefinition>;
tenancy: ClientFromDefinition<typeof TenancyDefinition>;
watch: ClientFromDefinition<typeof WatchDefinition>;
};

/**
* Create a new gRPC service client for Permify.
* The client can be configured with multiple client interceptors. For authentication interceptors,
Expand All @@ -19,7 +36,7 @@ import { Config } from './config';
*
* @returns A new gRPC service client for the Permission API of Permify.
*/
export function newClient(conf: Config, ...interceptors: ClientMiddleware[]) {
export function newClient(conf: Config, ...interceptors: ClientMiddleware[]): PermifyClient {
const channel = conf.insecure
? createChannel(conf.endpoint, ChannelCredentials.createInsecure())
: createChannel(conf.endpoint, ChannelCredentials.createSsl(conf.cert, conf.pk, conf.certChain));
Expand Down