ServiceKeysManager
Service Keys Manager
Manages service keys (anon and service) for tenant databases. Each tenant has their own auth.service_keys table.
Example
Section titled “Example”// List all service keysconst { data, error } = await client.admin.serviceKeys.list()
// Create a new service keyconst { data, error } = await client.admin.serviceKeys.create({ name: 'Production API Key', key_type: 'service', scopes: ['*']})
// Rotate a keyconst { data, error } = await client.admin.serviceKeys.rotate('key-id')Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ServiceKeysManager(
fetch):ServiceKeysManager
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fetch | FluxbaseFetch |
Returns
Section titled “Returns”ServiceKeysManager
Methods
Section titled “Methods”create()
Section titled “create()”create(
request):Promise<{data:ServiceKeyWithKey|null;error:Error|null; }>
Create a new service key
The full key value is only returned once - store it securely!
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
request | CreateServiceKeyRequest | Key creation options |
Returns
Section titled “Returns”Promise<{ data: ServiceKeyWithKey | null; error: Error | null; }>
Created key with full key value
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.create({ name: 'Production API Key', key_type: 'service', scopes: ['*'], rate_limit_per_minute: 1000})
if (data) { // Store data.key securely - it won't be shown again! console.log('Key created:', data.key)}delete()
Section titled “delete()”delete(
id):Promise<{error:Error|null; }>
Delete a service key permanently
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
Returns
Section titled “Returns”Promise<{ error: Error | null; }>
Success or error
Example
Section titled “Example”const { error } = await client.admin.serviceKeys.delete('key-id')deprecate()
Section titled “deprecate()”deprecate(
id,request?):Promise<{data: {deprecated_at:string;grace_period_ends_at:string; } |null;error:Error|null; }>
Deprecate a service key (graceful rotation)
Marks the key for removal but keeps it active during grace period.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
request? | DeprecateServiceKeyRequest | Deprecation options |
Returns
Section titled “Returns”Promise<{ data: { deprecated_at: string; grace_period_ends_at: string; } | null; error: Error | null; }>
Deprecation details
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.deprecate('key-id', { reason: 'Rotating to new key', grace_period_hours: 48})disable()
Section titled “disable()”disable(
id):Promise<{error:Error|null; }>
Disable a service key (temporarily)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
Returns
Section titled “Returns”Promise<{ error: Error | null; }>
Success or error
Example
Section titled “Example”const { error } = await client.admin.serviceKeys.disable('key-id')enable()
Section titled “enable()”enable(
id):Promise<{error:Error|null; }>
Enable a disabled service key
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
Returns
Section titled “Returns”Promise<{ error: Error | null; }>
Success or error
Example
Section titled “Example”const { error } = await client.admin.serviceKeys.enable('key-id')get(
id):Promise<{data:ServiceKey|null;error:Error|null; }>
Get a service key by ID
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
Returns
Section titled “Returns”Promise<{ data: ServiceKey | null; error: Error | null; }>
Service key details
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.get('key-id')getRevocationHistory()
Section titled “getRevocationHistory()”getRevocationHistory(
id):Promise<{data: {id:string;name:string;revocation_reason:string;revoked_at:string;revoked_by:string; } |null;error:Error|null; }>
Get revocation history for a service key
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
Returns
Section titled “Returns”Promise<{ data: { id: string; name: string; revocation_reason: string; revoked_at: string; revoked_by: string; } | null; error: Error | null; }>
Revocation history
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.getRevocationHistory('key-id')list()
Section titled “list()”list():
Promise<{data:ServiceKey[] |null;error:Error|null; }>
List all service keys
Returns
Section titled “Returns”Promise<{ data: ServiceKey[] | null; error: Error | null; }>
List of service keys
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.list()revoke()
Section titled “revoke()”revoke(
id,request?):Promise<{error:Error|null; }>
Revoke a service key permanently (emergency)
Use for immediate revocation when a key is compromised.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
request? | RevokeServiceKeyRequest | Revocation options |
Returns
Section titled “Returns”Promise<{ error: Error | null; }>
Success or error
Example
Section titled “Example”const { error } = await client.admin.serviceKeys.revoke('key-id', { reason: 'Key was compromised'})rotate()
Section titled “rotate()”rotate(
id):Promise<{data:ServiceKeyWithKey|null;error:Error|null; }>
Rotate a service key (create replacement)
Creates a new key with the same settings and deprecates the old one. The new key is returned with its full value.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID to rotate |
Returns
Section titled “Returns”Promise<{ data: ServiceKeyWithKey | null; error: Error | null; }>
New key with full key value
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.rotate('old-key-id')
if (data) { console.log('New key:', data.key) console.log('Old key deprecated at:', data.deprecated_at)}update()
Section titled “update()”update(
id,request):Promise<{data:ServiceKey|null;error:Error|null; }>
Update a service key
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Service key ID |
request | UpdateServiceKeyRequest | Update options |
Returns
Section titled “Returns”Promise<{ data: ServiceKey | null; error: Error | null; }>
Updated key
Example
Section titled “Example”const { data, error } = await client.admin.serviceKeys.update('key-id', { name: 'New Name', rate_limit_per_minute: 2000})