@nestarc/api-keys
Classes
ApiKeyError
Defined in: src/errors.ts:25
Extends
Error
Constructors
Constructor
new ApiKeyError(code, reason?): ApiKeyError;Defined in: src/errors.ts:29
Parameters
| Parameter | Type |
|---|---|
code | ApiKeyErrorCode |
reason? | string |
Returns
Overrides
Error.constructorProperties
cause?
optional cause?: unknown;Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26
Inherited from
Error.causecode
readonly code: ApiKeyErrorCode;Defined in: src/errors.ts:26
httpStatus
readonly httpStatus: number;Defined in: src/errors.ts:27
message
message: string;Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Inherited from
Error.messagename
name: string;Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Inherited from
Error.namestack?
optional stack?: string;Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Inherited from
Error.stackstackTraceLimit
static stackTraceLimit: number;Defined in: node_modules/@types/node/globals.d.ts:68
The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).
The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Inherited from
Error.stackTraceLimitMethods
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:52
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:56
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTraceApiKeyOperationError
Defined in: src/errors.ts:45
Extends
Error
Constructors
Constructor
new ApiKeyOperationError(code, reason?): ApiKeyOperationError;Defined in: src/errors.ts:48
Parameters
| Parameter | Type |
|---|---|
code | ApiKeyOperationErrorCode |
reason? | string |
Returns
Overrides
Error.constructorProperties
cause?
optional cause?: unknown;Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26
Inherited from
Error.causecode
readonly code: ApiKeyOperationErrorCode;Defined in: src/errors.ts:46
message
message: string;Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Inherited from
Error.messagename
name: string;Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Inherited from
Error.namestack?
optional stack?: string;Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Inherited from
Error.stackstackTraceLimit
static stackTraceLimit: number;Defined in: node_modules/@types/node/globals.d.ts:68
The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).
The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Inherited from
Error.stackTraceLimitMethods
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:52
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:56
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTraceApiKeysGuard
Defined in: src/api-keys.guard.ts:27
Implements
CanActivate
Constructors
Constructor
new ApiKeysGuard(
service,
reflector,
contextWriter?,
clientIpResolver?): ApiKeysGuard;Defined in: src/api-keys.guard.ts:28
Parameters
| Parameter | Type |
|---|---|
service | ApiKeysService |
reflector | Reflector |
contextWriter? | ApiKeyContextWriter |
clientIpResolver? | ApiKeyClientIpResolver |
Returns
Methods
canActivate()
canActivate(context): Promise<boolean>;Defined in: src/api-keys.guard.ts:39
Parameters
| Parameter | Type | Description |
|---|---|---|
context | ExecutionContext | Current execution context. Provides access to details about the current request pipeline. |
Returns
Promise<boolean>
Value indicating whether or not the current request is allowed to proceed.
Implementation of
CanActivate.canActivateApiKeysModule
Defined in: src/api-keys.module.ts:38
Constructors
Constructor
new ApiKeysModule(): ApiKeysModule;Returns
Methods
forRoot()
static forRoot(options): DynamicModule;Defined in: src/api-keys.module.ts:39
Parameters
| Parameter | Type |
|---|---|
options | ApiKeysModuleOptions |
Returns
DynamicModule
ApiKeysService
Defined in: src/api-keys.service.ts:46
Constructors
Constructor
new ApiKeysService(deps): ApiKeysService;Defined in: src/api-keys.service.ts:64
Parameters
| Parameter | Type |
|---|---|
deps | ApiKeysServiceDeps |
Returns
Methods
create()
create(input): Promise<CreateApiKeyResult>;Defined in: src/api-keys.service.ts:81
Parameters
| Parameter | Type |
|---|---|
input | CreateApiKeyInput |
Returns
Promise<CreateApiKeyResult>
list()
list(tenantId, opts?): Promise<ApiKeyRecord[]>;Defined in: src/api-keys.service.ts:337
Parameters
| Parameter | Type |
|---|---|
tenantId | string |
opts | { includeRevoked?: boolean; } |
opts.includeRevoked? | boolean |
Returns
Promise<ApiKeyRecord[]>
revoke()
revoke(id): Promise<void>;Defined in: src/api-keys.service.ts:228
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<void>
rotate()
rotate(id, input?): Promise<RotateApiKeyResult>;Defined in: src/api-keys.service.ts:243
Parameters
| Parameter | Type |
|---|---|
id | string |
input | RotateApiKeyInput |
Returns
Promise<RotateApiKeyResult>
verify()
verify(rawKey): Promise<ApiKeyContext>;Defined in: src/api-keys.service.ts:141
Parameters
| Parameter | Type |
|---|---|
rawKey | string |
Returns
Promise<ApiKeyContext>
InMemoryApiKeyStorage
Defined in: src/storage/in-memory-storage.ts:8
Implements
Constructors
Constructor
new InMemoryApiKeyStorage(): InMemoryApiKeyStorage;Returns
Methods
findById()
findById(id): Promise<ApiKeyRecord | null>;Defined in: src/storage/in-memory-storage.ts:23
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<ApiKeyRecord | null>
Implementation of
findByPrefix()
findByPrefix(prefix): Promise<ApiKeyRecord | null>;Defined in: src/storage/in-memory-storage.ts:28
Parameters
| Parameter | Type |
|---|---|
prefix | string |
Returns
Promise<ApiKeyRecord | null>
Implementation of
insert()
insert(record): Promise<void>;Defined in: src/storage/in-memory-storage.ts:11
Parameters
| Parameter | Type |
|---|---|
record | ApiKeyRecord |
Returns
Promise<void>
Implementation of
listByTenant()
listByTenant(tenantId, opts?): Promise<ApiKeyRecord[]>;Defined in: src/storage/in-memory-storage.ts:38
Parameters
| Parameter | Type |
|---|---|
tenantId | string |
opts | ListApiKeysOptions |
Returns
Promise<ApiKeyRecord[]>
Implementation of
markRevoked()
markRevoked(id, at): Promise<void>;Defined in: src/storage/in-memory-storage.ts:50
Parameters
| Parameter | Type |
|---|---|
id | string |
at | Date |
Returns
Promise<void>
Implementation of
rotate()
rotate(input): Promise<void>;Defined in: src/storage/in-memory-storage.ts:68
Parameters
| Parameter | Type |
|---|---|
input | RotateApiKeyStorageInput |
Returns
Promise<void>
Implementation of
touchLastUsed()
touchLastUsed(id, at): Promise<void>;Defined in: src/storage/in-memory-storage.ts:59
Parameters
| Parameter | Type |
|---|---|
id | string |
at | Date |
Returns
Promise<void>
Implementation of
PrismaApiKeyStorage
Defined in: src/storage/prisma-storage.ts:18
Implements
Constructors
Constructor
new PrismaApiKeyStorage(prisma): PrismaApiKeyStorage;Defined in: src/storage/prisma-storage.ts:19
Parameters
| Parameter | Type |
|---|---|
prisma | PrismaLike |
Returns
Methods
findById()
findById(id): Promise<ApiKeyRecord | null>;Defined in: src/storage/prisma-storage.ts:25
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<ApiKeyRecord | null>
Implementation of
findByPrefix()
findByPrefix(prefix): Promise<ApiKeyRecord | null>;Defined in: src/storage/prisma-storage.ts:35
Parameters
| Parameter | Type |
|---|---|
prefix | string |
Returns
Promise<ApiKeyRecord | null>
Implementation of
insert()
insert(record): Promise<void>;Defined in: src/storage/prisma-storage.ts:21
Parameters
| Parameter | Type |
|---|---|
record | ApiKeyRecord |
Returns
Promise<void>
Implementation of
listByTenant()
listByTenant(tenantId, opts?): Promise<ApiKeyRecord[]>;Defined in: src/storage/prisma-storage.ts:45
Parameters
| Parameter | Type |
|---|---|
tenantId | string |
opts | ListApiKeysOptions |
Returns
Promise<ApiKeyRecord[]>
Implementation of
markRevoked()
markRevoked(id, at): Promise<void>;Defined in: src/storage/prisma-storage.ts:62
Parameters
| Parameter | Type |
|---|---|
id | string |
at | Date |
Returns
Promise<void>
Implementation of
rotate()
rotate(input): Promise<void>;Defined in: src/storage/prisma-storage.ts:70
Parameters
| Parameter | Type |
|---|---|
input | RotateApiKeyStorageInput |
Returns
Promise<void>
Implementation of
touchLastUsed()
touchLastUsed(id, at): Promise<void>;Defined in: src/storage/prisma-storage.ts:66
Parameters
| Parameter | Type |
|---|---|
id | string |
at | Date |
Returns
Promise<void>
Implementation of
Sha256Hasher
Defined in: src/hasher.ts:13
Constructors
Constructor
new Sha256Hasher(options): Sha256Hasher;Defined in: src/hasher.ts:14
Parameters
| Parameter | Type |
|---|---|
options | HasherOptions |
Returns
Methods
dummyVerify()
dummyVerify(secret): boolean;Defined in: src/hasher.ts:40
Parameters
| Parameter | Type |
|---|---|
secret | string |
Returns
boolean
hash()
hash(secret): HashedSecret;Defined in: src/hasher.ts:20
Parameters
| Parameter | Type |
|---|---|
secret | string |
Returns
verify()
verify(
secret,
expectedHash,
pepperVersion): boolean;Defined in: src/hasher.ts:30
Parameters
| Parameter | Type |
|---|---|
secret | string |
expectedHash | string |
pepperVersion | number |
Returns
boolean
Interfaces
ApiKeyAuthFailedEvent
Defined in: src/types.ts:105
Extends
Properties
at
at: Date;Defined in: src/types.ts:71
Inherited from
code
code: ApiKeyErrorCode;Defined in: src/types.ts:108
environment?
optional environment?: Environment;Defined in: src/types.ts:111
keyId?
optional keyId?: string;Defined in: src/types.ts:110
prefix
prefix: string | null;Defined in: src/types.ts:107
tenantId?
optional tenantId?: string;Defined in: src/types.ts:109
type
type: "api_key.auth_failed";Defined in: src/types.ts:106
ApiKeyContext
Defined in: src/types.ts:31
Properties
allowedIpCidrs?
optional allowedIpCidrs?: string[];Defined in: src/types.ts:37
environment
environment: Environment;Defined in: src/types.ts:34
keyId
keyId: string;Defined in: src/types.ts:32
prefix
prefix: string;Defined in: src/types.ts:36
scopes
scopes: string[];Defined in: src/types.ts:35
tenantId
tenantId: string;Defined in: src/types.ts:33
ApiKeyCreatedEvent
Defined in: src/types.ts:74
Extends
Properties
at
at: Date;Defined in: src/types.ts:71
Inherited from
createdBy
createdBy: string | null;Defined in: src/types.ts:81
environment
environment: Environment;Defined in: src/types.ts:79
keyId
keyId: string;Defined in: src/types.ts:76
prefix
prefix: string;Defined in: src/types.ts:78
scopes
scopes: string[];Defined in: src/types.ts:80
tenantId
tenantId: string;Defined in: src/types.ts:77
type
type: "api_key.created";Defined in: src/types.ts:75
ApiKeyEventBase
Defined in: src/types.ts:70
Extended by
Properties
at
at: Date;Defined in: src/types.ts:71
ApiKeyRecord
Defined in: src/types.ts:12
Properties
allowedIpCidrs?
optional allowedIpCidrs?: string[];Defined in: src/types.ts:21
createdAt
createdAt: Date;Defined in: src/types.ts:28
createdBy
createdBy: string | null;Defined in: src/types.ts:27
environment
environment: Environment;Defined in: src/types.ts:16
expiresAt
expiresAt: Date | null;Defined in: src/types.ts:23
hash
hash: string;Defined in: src/types.ts:18
id
id: string;Defined in: src/types.ts:13
lastUsedAt
lastUsedAt: Date | null;Defined in: src/types.ts:22
name
name: string;Defined in: src/types.ts:15
pepperVersion
pepperVersion: number;Defined in: src/types.ts:19
prefix
prefix: string;Defined in: src/types.ts:17
replacedByKeyId
replacedByKeyId: string | null;Defined in: src/types.ts:26
revokedAt
revokedAt: Date | null;Defined in: src/types.ts:24
rotatedAt
rotatedAt: Date | null;Defined in: src/types.ts:25
scopes
scopes: string[];Defined in: src/types.ts:20
tenantId
tenantId: string;Defined in: src/types.ts:14
ApiKeyRevokedEvent
Defined in: src/types.ts:84
Extends
Properties
at
at: Date;Defined in: src/types.ts:71
Inherited from
environment
environment: Environment;Defined in: src/types.ts:89
keyId
keyId: string;Defined in: src/types.ts:86
prefix
prefix: string;Defined in: src/types.ts:88
tenantId
tenantId: string;Defined in: src/types.ts:87
type
type: "api_key.revoked";Defined in: src/types.ts:85
ApiKeyRotatedEvent
Defined in: src/types.ts:92
Extends
Properties
at
at: Date;Defined in: src/types.ts:71
Inherited from
createdBy
createdBy: string | null;Defined in: src/types.ts:102
environment
environment: Environment;Defined in: src/types.ts:99
graceExpiresAt
graceExpiresAt: Date;Defined in: src/types.ts:101
newKeyId
newKeyId: string;Defined in: src/types.ts:97
newPrefix
newPrefix: string;Defined in: src/types.ts:98
oldKeyId
oldKeyId: string;Defined in: src/types.ts:95
oldPrefix
oldPrefix: string;Defined in: src/types.ts:96
scopes
scopes: string[];Defined in: src/types.ts:100
tenantId
tenantId: string;Defined in: src/types.ts:94
type
type: "api_key.rotated";Defined in: src/types.ts:93
ApiKeysModuleOptions
Defined in: src/api-keys.module.ts:20
Properties
clientIpResolver?
optional clientIpResolver?: ApiKeyClientIpResolver;Defined in: src/api-keys.module.ts:34
contextWriter?
optional contextWriter?: ApiKeyContextWriter;Defined in: src/api-keys.module.ts:33
currentPepperVersion?
optional currentPepperVersion?: number;Defined in: src/api-keys.module.ts:23
debounceMs?
optional debounceMs?: number;Defined in: src/api-keys.module.ts:24
emitUsageEvents?
optional emitUsageEvents?: boolean;Defined in: src/api-keys.module.ts:31
namespace?
optional namespace?: string;Defined in: src/api-keys.module.ts:21
onAuthFailed?
optional onAuthFailed?: (prefix, code) => void;Defined in: src/api-keys.module.ts:26
Parameters
| Parameter | Type |
|---|---|
prefix | string | null |
code | string |
Returns
void
onEvent?
optional onEvent?: ApiKeyEventSink;Defined in: src/api-keys.module.ts:27
onEventError?
optional onEventError?: (error, event) => void;Defined in: src/api-keys.module.ts:28
Parameters
| Parameter | Type |
|---|---|
error | unknown |
event | ApiKeyEvent |
Returns
void
onMetric?
optional onMetric?: ApiKeyMetricSink;Defined in: src/api-keys.module.ts:29
onMetricError?
optional onMetricError?: (error, metric) => void;Defined in: src/api-keys.module.ts:30
Parameters
| Parameter | Type |
|---|---|
error | unknown |
metric | ApiKeyVerificationMetric |
Returns
void
peppers
peppers: Record<number, string>;Defined in: src/api-keys.module.ts:22
storage
storage: ApiKeyStorage;Defined in: src/api-keys.module.ts:25
ttlPolicy?
optional ttlPolicy?: ApiKeyTtlPolicy;Defined in: src/api-keys.module.ts:32
ApiKeysServiceDeps
Defined in: src/api-keys.service.ts:29
Properties
clock?
optional clock?: () => Date;Defined in: src/api-keys.service.ts:34
Returns
Date
debounceMs?
optional debounceMs?: number;Defined in: src/api-keys.service.ts:35
emitUsageEvents?
optional emitUsageEvents?: boolean;Defined in: src/api-keys.service.ts:41
hasher
hasher: Sha256Hasher;Defined in: src/api-keys.service.ts:31
idFactory?
optional idFactory?: () => string;Defined in: src/api-keys.service.ts:33
Returns
string
monotonicClock?
optional monotonicClock?: () => number;Defined in: src/api-keys.service.ts:43
Returns
number
namespace
namespace: string;Defined in: src/api-keys.service.ts:32
onAuthFailed?
optional onAuthFailed?: (prefix, code) => void;Defined in: src/api-keys.service.ts:36
Parameters
| Parameter | Type |
|---|---|
prefix | string | null |
code | string |
Returns
void
onEvent?
optional onEvent?: ApiKeyEventSink;Defined in: src/api-keys.service.ts:37
onEventError?
optional onEventError?: (error, event) => void;Defined in: src/api-keys.service.ts:38
Parameters
| Parameter | Type |
|---|---|
error | unknown |
event | ApiKeyEvent |
Returns
void
onMetric?
optional onMetric?: ApiKeyMetricSink;Defined in: src/api-keys.service.ts:39
onMetricError?
optional onMetricError?: (error, metric) => void;Defined in: src/api-keys.service.ts:40
Parameters
| Parameter | Type |
|---|---|
error | unknown |
metric | ApiKeyVerificationMetric |
Returns
void
storage
storage: ApiKeyStorage;Defined in: src/api-keys.service.ts:30
ttlPolicy?
optional ttlPolicy?: ApiKeyTtlPolicy;Defined in: src/api-keys.service.ts:42
ApiKeyStorage
Defined in: src/storage/api-key-storage.interface.ts:14
Methods
findById()
findById(id): Promise<ApiKeyRecord | null>;Defined in: src/storage/api-key-storage.interface.ts:16
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<ApiKeyRecord | null>
findByPrefix()
findByPrefix(prefix): Promise<ApiKeyRecord | null>;Defined in: src/storage/api-key-storage.interface.ts:17
Parameters
| Parameter | Type |
|---|---|
prefix | string |
Returns
Promise<ApiKeyRecord | null>
insert()
insert(record): Promise<void>;Defined in: src/storage/api-key-storage.interface.ts:15
Parameters
| Parameter | Type |
|---|---|
record | ApiKeyRecord |
Returns
Promise<void>
listByTenant()
listByTenant(tenantId, opts?): Promise<ApiKeyRecord[]>;Defined in: src/storage/api-key-storage.interface.ts:18
Parameters
| Parameter | Type |
|---|---|
tenantId | string |
opts? | ListApiKeysOptions |
Returns
Promise<ApiKeyRecord[]>
markRevoked()
markRevoked(id, at): Promise<void>;Defined in: src/storage/api-key-storage.interface.ts:19
Parameters
| Parameter | Type |
|---|---|
id | string |
at | Date |
Returns
Promise<void>
rotate()
rotate(input): Promise<void>;Defined in: src/storage/api-key-storage.interface.ts:21
Parameters
| Parameter | Type |
|---|---|
input | RotateApiKeyStorageInput |
Returns
Promise<void>
touchLastUsed()
touchLastUsed(id, at): Promise<void>;Defined in: src/storage/api-key-storage.interface.ts:20
Parameters
| Parameter | Type |
|---|---|
id | string |
at | Date |
Returns
Promise<void>
ApiKeyTtlPolicy
Defined in: src/types.ts:149
Properties
allowNeverExpires?
optional allowNeverExpires?: boolean;Defined in: src/types.ts:152
defaultExpiresInMs?
optional defaultExpiresInMs?: number;Defined in: src/types.ts:150
maxExpiresInMs?
optional maxExpiresInMs?: number;Defined in: src/types.ts:151
ApiKeyUsedEvent
Defined in: src/types.ts:114
Extends
Properties
at
at: Date;Defined in: src/types.ts:71
Inherited from
environment
environment: Environment;Defined in: src/types.ts:119
keyId
keyId: string;Defined in: src/types.ts:116
prefix
prefix: string;Defined in: src/types.ts:118
scopes
scopes: string[];Defined in: src/types.ts:120
tenantId
tenantId: string;Defined in: src/types.ts:117
type
type: "api_key.used";Defined in: src/types.ts:115
ApiKeyVerificationMetric
Defined in: src/types.ts:140
Properties
durationMs
durationMs: number;Defined in: src/types.ts:143
environment?
optional environment?: Environment;Defined in: src/types.ts:144
outcome
outcome: ApiKeyVerificationOutcome;Defined in: src/types.ts:142
type
type: "api_key.verification";Defined in: src/types.ts:141
CreateApiKeyInput
Defined in: src/types.ts:40
Properties
allowedIpCidrs?
optional allowedIpCidrs?: string[];Defined in: src/types.ts:47
createdBy?
optional createdBy?: string;Defined in: src/types.ts:46
environment?
optional environment?: Environment;Defined in: src/types.ts:43
expiresAt?
optional expiresAt?: Date;Defined in: src/types.ts:45
name
name: string;Defined in: src/types.ts:42
scopes
scopes: Scope[];Defined in: src/types.ts:44
tenantId
tenantId: string;Defined in: src/types.ts:41
CreateApiKeyResult
Defined in: src/types.ts:50
Properties
id
id: string;Defined in: src/types.ts:51
key
key: string;Defined in: src/types.ts:52
CreateTestKeyOptions
Defined in: src/testing.ts:4
Properties
allowedIpCidrs?
optional allowedIpCidrs?: string[];Defined in: src/testing.ts:11
createdBy?
optional createdBy?: string;Defined in: src/testing.ts:10
environment?
optional environment?: Environment;Defined in: src/testing.ts:7
expiresAt?
optional expiresAt?: Date;Defined in: src/testing.ts:9
name?
optional name?: string;Defined in: src/testing.ts:6
scopes?
optional scopes?: Scope[];Defined in: src/testing.ts:8
tenantId?
optional tenantId?: string;Defined in: src/testing.ts:5
HashedSecret
Defined in: src/hasher.ts:3
Properties
hash
hash: string;Defined in: src/hasher.ts:4
pepperVersion
pepperVersion: number;Defined in: src/hasher.ts:5
HasherOptions
Defined in: src/hasher.ts:8
Properties
currentVersion
currentVersion: number;Defined in: src/hasher.ts:10
peppers
peppers: Record<number, string>;Defined in: src/hasher.ts:9
ListApiKeysOptions
Defined in: src/storage/api-key-storage.interface.ts:3
Properties
includeRevoked?
optional includeRevoked?: boolean;Defined in: src/storage/api-key-storage.interface.ts:4
PrismaLike
Defined in: src/storage/prisma-storage.ts:8
Properties
apiKey
apiKey: {
create: Promise<unknown>;
findMany: Promise<unknown[]>;
findUnique: Promise<unknown>;
update: Promise<unknown>;
};Defined in: src/storage/prisma-storage.ts:9
create()
create(args): Promise<unknown>;Parameters
| Parameter | Type |
|---|---|
args | { data: unknown; } |
args.data | unknown |
Returns
Promise<unknown>
findMany()
findMany(args): Promise<unknown[]>;Parameters
| Parameter | Type |
|---|---|
args | { orderBy?: unknown; where: unknown; } |
args.orderBy? | unknown |
args.where | unknown |
Returns
Promise<unknown[]>
findUnique()
findUnique(args): Promise<unknown>;Parameters
| Parameter | Type |
|---|---|
args | { where: | { prefix: string; } | { id: string; }; } |
args.where | | { prefix: string; } | { id: string; } |
Returns
Promise<unknown>
update()
update(args): Promise<unknown>;Parameters
| Parameter | Type |
|---|---|
args | { data: unknown; where: { id: string; }; } |
args.data | unknown |
args.where | { id: string; } |
args.where.id | string |
Returns
Promise<unknown>
Methods
$transaction()?
optional $transaction<T>(operations): Promise<T[]>;Defined in: src/storage/prisma-storage.ts:15
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
operations | Promise<T>[] |
Returns
Promise<T[]>
RequiredScope
Defined in: src/decorators/require-scope.decorator.ts:6
Properties
level
level: ScopeLevel;Defined in: src/decorators/require-scope.decorator.ts:8
resource
resource: string;Defined in: src/decorators/require-scope.decorator.ts:7
RotateApiKeyInput
Defined in: src/types.ts:55
Properties
allowedIpCidrs?
optional allowedIpCidrs?: string[];Defined in: src/types.ts:60
createdBy?
optional createdBy?: string;Defined in: src/types.ts:58
expiresAt?
optional expiresAt?: Date | null;Defined in: src/types.ts:59
gracePeriodMs?
optional gracePeriodMs?: number;Defined in: src/types.ts:56
name?
optional name?: string;Defined in: src/types.ts:57
RotateApiKeyResult
Defined in: src/types.ts:63
Properties
graceExpiresAt
graceExpiresAt: Date;Defined in: src/types.ts:67
id
id: string;Defined in: src/types.ts:64
key
key: string;Defined in: src/types.ts:65
replacedKeyId
replacedKeyId: string;Defined in: src/types.ts:66
RotateApiKeyStorageInput
Defined in: src/storage/api-key-storage.interface.ts:7
Properties
newRecord
newRecord: ApiKeyRecord;Defined in: src/storage/api-key-storage.interface.ts:9
oldExpiresAt
oldExpiresAt: Date;Defined in: src/storage/api-key-storage.interface.ts:10
oldKeyId
oldKeyId: string;Defined in: src/storage/api-key-storage.interface.ts:8
rotatedAt
rotatedAt: Date;Defined in: src/storage/api-key-storage.interface.ts:11
Scope
Defined in: src/types.ts:7
Properties
level
level: ScopeLevel;Defined in: src/types.ts:9
resource
resource: string;Defined in: src/types.ts:8
Type Aliases
ApiKeyClientIpResolver
type ApiKeyClientIpResolver = (request) => string | undefined | Promise<string | undefined>;Defined in: src/ip-allowlist.ts:5
Parameters
| Parameter | Type |
|---|---|
request | unknown |
Returns
string | undefined | Promise<string | undefined>
ApiKeyContextWriter
type ApiKeyContextWriter = (apiKey, request) => void | Promise<void>;Defined in: src/context.ts:6
Parameters
| Parameter | Type |
|---|---|
apiKey | ApiKeyContext |
request | unknown |
Returns
void | Promise<void>
ApiKeyErrorCode
type ApiKeyErrorCode = typeof ApiKeyErrorCode[keyof typeof ApiKeyErrorCode];Defined in: src/errors.ts:1
ApiKeyEvent
type ApiKeyEvent =
| ApiKeyCreatedEvent
| ApiKeyRevokedEvent
| ApiKeyRotatedEvent
| ApiKeyAuthFailedEvent
| ApiKeyUsedEvent;Defined in: src/types.ts:123
ApiKeyEventSink
type ApiKeyEventSink = (event) => void | Promise<void>;Defined in: src/types.ts:130
Parameters
| Parameter | Type |
|---|---|
event | ApiKeyEvent |
Returns
void | Promise<void>
ApiKeyMetricSink
type ApiKeyMetricSink = (metric) => void | Promise<void>;Defined in: src/types.ts:147
Parameters
| Parameter | Type |
|---|---|
metric | ApiKeyVerificationMetric |
Returns
void | Promise<void>
ApiKeyOperationErrorCode
type ApiKeyOperationErrorCode = typeof ApiKeyOperationErrorCode[keyof typeof ApiKeyOperationErrorCode];Defined in: src/errors.ts:37
ApiKeyVerificationOutcome
type ApiKeyVerificationOutcome = "success" | "malformed" | "invalid" | "revoked" | "expired" | "error";Defined in: src/types.ts:132
Environment
type Environment = "live" | "test";Defined in: src/types.ts:3
ScopeLevel
type ScopeLevel = "read" | "write";Defined in: src/types.ts:5
Variables
API_KEY_CLIENT_IP_RESOLVER
const API_KEY_CLIENT_IP_RESOLVER: typeof API_KEY_CLIENT_IP_RESOLVER;Defined in: src/ip-allowlist.ts:3
API_KEY_CONTEXT_PROPERTY
const API_KEY_CONTEXT_PROPERTY: "apiKey" = 'apiKey';Defined in: src/context.ts:3
API_KEY_CONTEXT_WRITER
const API_KEY_CONTEXT_WRITER: typeof API_KEY_CONTEXT_WRITER;Defined in: src/context.ts:4
API_KEY_REDACT_REGEX
const API_KEY_REDACT_REGEX: RegExp;Defined in: src/key-format.ts:77
API_KEYS_OPTIONS
const API_KEYS_OPTIONS: typeof API_KEYS_OPTIONS;Defined in: src/api-keys.module.ts:17
API_KEYS_STORAGE
const API_KEYS_STORAGE: typeof API_KEYS_STORAGE;Defined in: src/api-keys.module.ts:18
ApiKeyErrorCode
const ApiKeyErrorCode: {
EnvironmentMismatch: "api_key_environment_mismatch";
Expired: "api_key_expired";
Invalid: "api_key_invalid";
IpNotAllowed: "api_key_ip_not_allowed";
Malformed: "api_key_malformed";
Missing: "api_key_missing";
Revoked: "api_key_revoked";
ScopeInsufficient: "api_key_scope_insufficient";
};Defined in: src/errors.ts:1
Type Declaration
| Name | Type | Default value | Defined in |
|---|---|---|---|
EnvironmentMismatch | "api_key_environment_mismatch" | 'api_key_environment_mismatch' | src/errors.ts:7 |
Expired | "api_key_expired" | 'api_key_expired' | src/errors.ts:6 |
Invalid | "api_key_invalid" | 'api_key_invalid' | src/errors.ts:4 |
IpNotAllowed | "api_key_ip_not_allowed" | 'api_key_ip_not_allowed' | src/errors.ts:9 |
Malformed | "api_key_malformed" | 'api_key_malformed' | src/errors.ts:3 |
Missing | "api_key_missing" | 'api_key_missing' | src/errors.ts:2 |
Revoked | "api_key_revoked" | 'api_key_revoked' | src/errors.ts:5 |
ScopeInsufficient | "api_key_scope_insufficient" | 'api_key_scope_insufficient' | src/errors.ts:8 |
ApiKeyOperationErrorCode
const ApiKeyOperationErrorCode: {
NotFound: "api_key_record_not_found";
NotRotatable: "api_key_not_rotatable";
};Defined in: src/errors.ts:37
Type Declaration
| Name | Type | Default value | Defined in |
|---|---|---|---|
NotFound | "api_key_record_not_found" | 'api_key_record_not_found' | src/errors.ts:38 |
NotRotatable | "api_key_not_rotatable" | 'api_key_not_rotatable' | src/errors.ts:39 |
CurrentApiKey
const CurrentApiKey: (...dataOrPipes) => ParameterDecorator;Defined in: src/decorators/current-api-key.decorator.ts:4
Parameters
| Parameter | Type |
|---|---|
...dataOrPipes | unknown[] |
Returns
ParameterDecorator
defaultApiKeyClientIpResolver
const defaultApiKeyClientIpResolver: ApiKeyClientIpResolver;Defined in: src/ip-allowlist.ts:9
ENVIRONMENT_METADATA
const ENVIRONMENT_METADATA: "nestarc:api-keys:environment" = 'nestarc:api-keys:environment';Defined in: src/decorators/require-environment.decorator.ts:4
SCOPE_METADATA
const SCOPE_METADATA: "nestarc:api-keys:scope" = 'nestarc:api-keys:scope';Defined in: src/decorators/require-scope.decorator.ts:4
Functions
createTestKey()
function createTestKey(service, options?): Promise<CreateApiKeyResult & {
context: ApiKeyContext;
}>;Defined in: src/testing.ts:14
Parameters
| Parameter | Type |
|---|---|
service | ApiKeysService |
options | CreateTestKeyOptions |
Returns
Promise<CreateApiKeyResult & { context: ApiKeyContext; }>
flattenScopes()
function flattenScopes(scopes): string[];Defined in: src/scope-matcher.ts:3
Parameters
| Parameter | Type |
|---|---|
scopes | Scope[] |
Returns
string[]
generateKey()
function generateKey(options): GeneratedKey;Defined in: src/key-format.ts:29
Parameters
| Parameter | Type |
|---|---|
options | { environment: Environment; namespace: string; } |
options.environment | Environment |
options.namespace | string |
Returns
GeneratedKey
getApiKeyContext()
function getApiKeyContext(request): ApiKeyContext | undefined;Defined in: src/context.ts:11
Parameters
| Parameter | Type |
|---|---|
request | unknown |
Returns
ApiKeyContext | undefined
isIpAllowed()
function isIpAllowed(clientIp, allowedIpCidrs): boolean;Defined in: src/ip-allowlist.ts:22
Parameters
| Parameter | Type |
|---|---|
clientIp | string | undefined |
allowedIpCidrs | readonly string[] |
Returns
boolean
normalizeAllowedIpCidrs()
function normalizeAllowedIpCidrs(entries?): string[];Defined in: src/ip-allowlist.ts:18
Parameters
| Parameter | Type | Default value |
|---|---|---|
entries | readonly string[] | [] |
Returns
string[]
parseKey()
function parseKey(raw): ParsedKey;Defined in: src/key-format.ts:53
Parameters
| Parameter | Type |
|---|---|
raw | string |
Returns
ParsedKey
RequireEnvironment()
function RequireEnvironment(environment): CustomDecorator<string>;Defined in: src/decorators/require-environment.decorator.ts:6
Parameters
| Parameter | Type |
|---|---|
environment | Environment |
Returns
CustomDecorator<string>
RequireScope()
function RequireScope(resource, level): CustomDecorator<string>;Defined in: src/decorators/require-scope.decorator.ts:11
Parameters
| Parameter | Type |
|---|---|
resource | string |
level | ScopeLevel |
Returns
CustomDecorator<string>
scopeSatisfies()
function scopeSatisfies(
granted,
resource,
required): boolean;Defined in: src/scope-matcher.ts:11
Parameters
| Parameter | Type |
|---|---|
granted | string[] |
resource | string |
required | ScopeLevel |
Returns
boolean