インターフェース
このドキュメントでは、MBC CQRS Serverlessフレームワークで使用されるすべてのTypeScriptインターフェースの包括的なリファレンスを提供します。
コアインターフェース
コマンドインターフェース
CommandInputModel
新しいコマンドを作成するためのプライマリインターフェース。新しいエンティティを発行する際に使用します。
export interface CommandInputModel {
pk: string // Partition key (e.g., "ORDER#tenant001")
sk: string // Sort key with version (e.g., "ORDER#ORD001#v0")
id: string // Unique identifier (e.g., UUID)
code: string // Business code (e.g., "ORD001")
name: string // Display name
version: number // Version number for optimistic locking
tenantCode: string // Tenant identifier
type: string // Entity type (e.g., "ORDER")
isDeleted?: boolean // Soft delete flag
seq?: number // Sequence number (auto-generated)
ttl?: number // Time-to-live timestamp (Unix epoch)
attributes?: Record<string, any> // Custom domain attributes
}
使用例:
const orderInput: CommandInputModel = {
pk: 'ORDER#tenant001',
sk: 'ORDER#ORD001#v0',
id: crypto.randomUUID(),
code: 'ORD001',
name: 'Customer Order',
version: 1,
tenantCode: 'tenant001',
type: 'ORDER',
attributes: {
customerId: 'CUST001',
totalAmount: 1500,
status: 'pending',
},
};
CommandPartialInputModel
部分更新に使用します。pk、sk、versionのみが必須です。
export interface CommandPartialInputModel extends Partial<CommandInputModel> {
pk: string // Required: Partition key
sk: string // Required: Sort key
version: number // Required: Current version for optimistic locking
}
使用例:
const partialUpdate: CommandPartialInputModel = {
pk: 'ORDER#tenant001',
sk: 'ORDER#ORD001',
version: 2, // Must match current version
name: 'Updated Order Name',
attributes: {
status: 'confirmed',
},
};
ICommandOptions
コマンド発行メソッドに渡されるオプション。
export interface ICommandOptions {
source?: string // Source identifier for tracking
requestId?: string // Request ID for tracing
invokeContext: IInvoke // Required: Invocation context
}
使用例:
const options: ICommandOptions = {
source: 'order-service',
requestId: context.awsRequestId,
invokeContext: {
userContext: getUserContext(event),
tenantCode: 'tenant001',
},
};
キーインターフェース
DetailKey
DynamoDBアイテムのプライマリキーを表します。
export interface DetailKey {
pk: string // Partition key
sk: string // Sort key
}
コンテキストインターフェース
IInvoke
Lambda/Expressのイベントとコンテキストを含む呼び出しコンテキスト。
export interface IInvoke {
event?: IInvokeEvent // Request event (headers, requestContext等のリクエストイベント)
context?: IInvokeContext // Lambda context (requestId, functionName等のLambdaコンテキスト)
}
IInvokeEvent
API GatewayまたはExpressからのHTTPリクエストイベント構造。
export interface IInvokeEvent {
version?: string
routeKey?: string // e.g., "POST /api/resource" (例: "POST /api/resource")
rawPath?: string
rawQueryString?: string
headers?: Record<string, string>
requestContext?: {
accountId?: string
apiId?: string
domainName?: string
domainPrefix?: string
http?: {
method?: string
path?: string
protocol?: string
sourceIp?: string // Client IP address (クライアントIPアドレス)
userAgent?: string
}
requestId?: string
stage?: string
time?: string
timeEpoch?: number
authorizer?: {
jwt?: {
claims?: JwtClaims // Decoded JWT claims (デコードされたJWTクレーム)
scopes?: string[]
}
}
}
isBase64Encoded?: boolean
}
IInvokeContext
Lambda実行コンテキスト情報。
export interface IInvokeContext {
functionName?: string // Lambda function name (Lambda関数名)
functionVersion?: string // Lambda function version (Lambda関数バージョン)
invokedFunctionArn?: string // Lambda ARN (Lambda ARN)
memoryLimitInMB?: string // Memory limit (メモリ制限)
awsRequestId?: string // AWS request ID for tracing (トレース用AWSリクエストID)
logGroupName?: string // CloudWatch log group (CloudWatchロググループ)
logStreamName?: string // CloudWatch log stream (CloudWatchログストリーム)
identity?: {
cognitoIdentityId?: string
cognitoIdentityPoolId?: string
}
}
JwtClaims
CognitoからのJWTトークンクレーム構造。
export interface JwtClaims {
sub: string // Cognito user ID (UUID) (CognitoユーザーID)
iss: string // Token issuer URL (トークン発行者URL)
username?: string
'cognito:groups'?: string[] // Cognito groups the user belongs to (ユーザーが所属するCognitoグループ)
'cognito:username': string // Cognito username (Cognitoユーザー名)
origin_jti?: string // Original JWT ID (元のJWT ID)
client_id?: string // OAuth client ID (OAuthクライアントID)
scope?: string // OAuth scopes (OAuthスコープ)
aud: string // Audience (client ID) (オーディエンス/クライアントID)
event_id: string
token_use: string // Token type (id or access) (トークンタイプ: id または access)
auth_time: number // Authentication timestamp (認証タイムスタンプ)
name: string // User's display name (ユーザー表示名)
'custom:tenant'?: string // Custom claim for tenant code (テナントコード用カスタムクレーム)
'custom:roles'?: string // Custom claim for roles JSON array (ロールJSON配列用カスタムクレーム)
exp: number // Token expiration timestamp (トークン有効期限タイムスタンプ)
email: string
email_verified?: boolean
iat: number // Token issued at timestamp (トークン発行タイムスタンプ)
jti: string // JWT ID (JWT ID)
}
カスタムクレームの例:
// The custom:roles claim contains a JSON array of role assignments (custom:rolesクレームはロール割り当てのJSON配列を含む)
// [{"tenant":"","role":"user"},{"tenant":"9999","role":"admin"}]
// - Empty tenant ("") means the role applies globally (空のテナント("")はロールがグローバルに適用されることを意味する)
// - Specific tenant means the role applies only to that tenant (特定のテナントはロールがそのテナントのみに適用されることを意味する)
UserContext
認証トークンから抽出されるユーザーコンテキストクラス。
export class UserContext {
userId: string // Cognito user ID (from JWT sub claim)
tenantRole: string // User's role within the tenant
tenantCode: string // Current tenant code
constructor(partial: Partial<UserContext>) // Initialize with partial properties (部分的なプロパティで初期化)
}
使用例:
import { getUserContext, IInvoke } from '@mbc-cqrs-serverless/core';
// Extract user context from IInvoke or ExecutionContext
const userContext = getUserContext(invokeContext);
console.log(userContext.userId); // '92ca4f68-9ac6-4080-9ae2-2f02a86206a4'
console.log(userContext.tenantCode); // 'tenant001'
console.log(userContext.tenantRole); // 'admin'