Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NK-579 Update satori client to latest API #159

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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[]
Expand All @@ -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[]
Expand All @@ -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)
}
}
38 changes: 36 additions & 2 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
}
Loading