diff --git a/index.d.ts b/index.d.ts index f18794b..674ac06 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5014,6 +5014,11 @@ declare namespace nkruntime { recompute?: boolean } + export interface AuthPropertiesUpdate { + default?: {[key: string]: string} + custom?: {[key: string]: string} + } + export interface SatoriEvent { name: string id: string @@ -5039,6 +5044,32 @@ declare namespace nkruntime { value: string activeStartTime: number activeEndTime: number + id: string + startTime: number + endTime: number + duration: number + resetCron: string + } + + export interface MessagesList { + messages: Message[] + nextCursor: string + prevCursor: string + cacheableCursor: string + } + + export interface Message { + scheduleId: string + sendTime: number + metadata: {[key: string]: string} + createTime: number + updateTime: number + readTime: number + consumeTime: number + text: string + id: string + title: string + imageUrl: string } /** @@ -5049,10 +5080,11 @@ declare namespace nkruntime { * Create identity. * * @param id - Identity identifier. + * @param properties - Opt. Properties to update. * @param ipAddress - Opt. Client IP address to pass on to Satori for geo-IP lookup. * @throws {TypeError, GoError} */ - authenticate(id: string, ipAddress?: string): void + authenticate(id: string, properties?: AuthPropertiesUpdate, ipAddress?: string): void /** * Get identity properties. @@ -5086,6 +5118,7 @@ declare namespace nkruntime { * * @param id - Identity identifier. * @param names - Opt. List of experiment names. + * @returns a list of experiments. * @throws {TypeError, GoError} */ experimentsList(id: string, names?: string[]): Experiment[] @@ -5095,6 +5128,7 @@ declare namespace nkruntime { * * @param id - Identity identifier. * @param names - Opt. List of flag names. + * @returns a List of flags. * @throws {TypeError, GoError} */ flagsList(id: string, names?: string[]): Flag[] @@ -5104,8 +5138,40 @@ declare namespace nkruntime { * * @param id - Identity identifier. * @param names - Opt. List of live event names. + * @returns a list of live-events. * @throws {TypeError, GoError} */ liveEventsList(id: string, names?: string[]): LiveEvent[] + + /** + * List messages. + * + * @param id - Identity identifier. + * @param limit - Opt. The max number of messages to return. + * @param forward - Opt. True if listing should be older messages to newer, false if reverse. + * @param cursor - Opt. A pagination cursor, if any. + * @returns A list of messages. + * @throws {TypeError, GoError} + */ + messagesList(id: string, limit?: number, forward?: boolean, cursor?: string): MessagesList[] + + /** + * Update a message. + * + * @param id - Identity identifier. + * @param readTime - The time the message was read at the client. + * @param consumeTime - Opt. The time the message was consumed by the identity. + * @throws {TypeError, GoError} + */ + messageUpdate(id: string, messageId: string, readTime: number, consumeTime?: number) + + /** + * Delete a message. + * + * @param id - Identity identifier. + * @param messageId - The identifier of the message. + * @throws {TypeError, GoError} + */ + messageDelete(id: string, messageId: string) } } diff --git a/runtime/runtime.go b/runtime/runtime.go index 147b6f5..73b13cc 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -90,12 +90,12 @@ import ( "database/sql" "errors" "fmt" - "google.golang.org/protobuf/types/known/timestamppb" "os" "time" "github.com/heroiclabs/nakama-common/api" "github.com/heroiclabs/nakama-common/rtapi" + "google.golang.org/protobuf/types/known/timestamppb" ) const ( @@ -1311,13 +1311,16 @@ type FleetManagerInitializer interface { Satori runtime integration definitions. */ type Satori interface { - Authenticate(ctx context.Context, id string, ipAddress ...string) error + Authenticate(ctx context.Context, id string, defaultProperties, customProperties map[string]string, ipAddress ...string) error PropertiesGet(ctx context.Context, id string) (*Properties, error) PropertiesUpdate(ctx context.Context, id string, properties *PropertiesUpdate) error EventsPublish(ctx context.Context, id string, events []*Event) error ExperimentsList(ctx context.Context, id string, names ...string) (*ExperimentList, error) FlagsList(ctx context.Context, id string, names ...string) (*FlagList, error) LiveEventsList(ctx context.Context, id string, names ...string) (*LiveEventList, error) + MessagesList(ctx context.Context, id string, limit int, forward bool, cursor string) (*MessageList, error) + MessageUpdate(ctx context.Context, id, messageId string, readTime, consumeTime int64) error + MessageDelete(ctx context.Context, id, messageId string) error } type Properties struct { @@ -1373,4 +1376,35 @@ type LiveEvent struct { Value string `json:"value,omitempty"` ActiveStartTimeSec int64 `json:"active_start_time_sec,string,omitempty"` ActiveEndTimeSec int64 `json:"active_end_time_sec,string,omitempty"` + Id string `json:"id,omitempty"` + StartTimeSec int64 `json:"start_time_sec,string,omitempty"` + EndTimeSec int64 `json:"end_time_sec,string,omitempty"` + DurationSec int64 `json:"duration_sec,string,omitempty"` + ResetCronExpr string `json:"reset_cron,omitempty"` +} + +type MessageList struct { + Messages []*Message `json:"messages,omitempty"` + NextCursor string `json:"next_cursor,omitempty"` + PrevCursor string `json:"prev_cursor,omitempty"` + CacheableCursor string `json:"cacheable_cursor,omitempty"` +} + +type Message struct { + ScheduleId string `json:"schedule_id,omitempty"` + SendTime int64 `json:"send_time,string,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` + CreateTime int64 `json:"create_time,string,omitempty"` + UpdateTime int64 `json:"update_time,string,omitempty"` + ReadTime int64 `json:"read_time,string,omitempty"` + ConsumeTime int64 `json:"consume_time,string,omitempty"` + Text string `json:"text,omitempty"` + Id string `json:"id,omitempty"` + Title string `json:"title,omitempty"` + ImageUrl string `json:"image_url,omitempty"` +} + +type MessageUpdate struct { + ReadTime int64 `json:"read_time,omitempty"` + ConsumeTime int64 `json:"consume_time,omitempty"` }