Permify TypeScript Client
raw JSON →permify-typescript is the official TypeScript client for Permify, an open-source authorization service designed for building fine-grained and scalable authorization systems. This package provides a programmatic interface to interact with the Permify API, covering operations for schema, relationships, permissions, and tenancy. As of version 1.6.9, the client's versioning now directly aligns with the upstream Permify API/OpenAPI version, ensuring closer synchronization with the service's capabilities. It is automatically generated by the OpenAPI Generator project, which ensures a consistent and up-to-date interface to the Permify API. The library supports Node.js environments version 18 and higher, shipping with full TypeScript type definitions for an enhanced developer experience.
Common errors
error Error: connect ECONNREFUSED 127.0.0.1:3476 ↓
http://localhost:3476). Check firewall settings or network connectivity issues. error Error: Request failed with status code 401 ↓
PERMIFY_API_KEY environment variable (or hardcoded token) is correct and that the Authorization header is properly formatted (e.g., Bearer YOUR_TOKEN). error TypeError: permify.Configuration is not a constructor ↓
import statements (e.g., import { Configuration } from 'permify-typescript'; or import * as permify from 'permify-typescript';) and that your Node.js project is configured to run ESM (e.g., by setting "type": "module" in your package.json). Warnings
gotcha Starting with v1.6.9, `permify-typescript` versions directly align with the upstream Permify API/OpenAPI version. A jump in the client's major or minor version number does not necessarily imply a breaking change in the SDK itself, but rather an update to match the Permify service's capabilities. Always refer to the package's specific release notes. ↓
breaking The `permify-typescript` package specifies Node.js version 18 or higher as a minimum requirement. Running on older Node.js versions may lead to unexpected runtime errors, dependency conflicts, or installation failures. ↓
gotcha API requests require proper authentication. Failure to provide a valid `Authorization` header (e.g., a Bearer token) will result in API authentication failures, typically a 401 Unauthorized response from the Permify API. ↓
Install
npm install permify-typescript yarn add permify-typescript pnpm add permify-typescript Imports
- permify (all exports) wrong
const permify = require('permify-typescript');correctimport * as permify from 'permify-typescript'; - Configuration, TenancyApi, PermissionApi wrong
import Configuration from 'permify-typescript/Configuration';correctimport { Configuration, TenancyApi, PermissionApi } from 'permify-typescript'; - Tenant (type) wrong
import { Tenant } from 'permify-typescript';correctimport type { Tenant } from 'permify-typescript';
Quickstart
import * as permify from "permify-typescript";
// Configure the client with your Permify API base path and authorization token.
// It's recommended to use environment variables for sensitive data.
const configuration = new permify.Configuration({
basePath: process.env.PERMIFY_API_BASE_PATH ?? "http://localhost:3476",
headers: {
'Authorization': process.env.PERMIFY_API_KEY ? `Bearer ${process.env.PERMIFY_API_KEY}` : ""
}
});
// Initialize the TenancyApi to interact with tenant-related endpoints.
const apiInstance = new permify.TenancyApi(configuration);
// Define a tenant ID, perhaps from a database or a unique identifier.
let tenantId = "example_tenant_id";
// Create a new tenant in Permify.
apiInstance.tenantsCreate({
body: {
id: tenantId,
name: "Example Tenant"
}
})
.then((data) => {
console.log('API called successfully. Created tenant: ' + JSON.stringify(data.tenant));
})
.catch((error) => {
console.error('Error creating tenant:', error.response?.data || error.message);
});