Skip to content

Commit

Permalink
Add Satori runtime integration (#116)
Browse files Browse the repository at this point in the history
Update TS definitions to include Satori functions.
  • Loading branch information
sesposito committed Mar 21, 2023
1 parent 05f3d08 commit d8dca07
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 26 deletions.
36 changes: 18 additions & 18 deletions api/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/heroiclabs/nakama-common

go 1.14
go 1.19

require google.golang.org/protobuf v1.28.1
120 changes: 116 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4107,13 +4107,13 @@ declare namespace nkruntime {
leaderboardDelete(leaderboardID: string): void;

/**
* Get a list of tournaments by id.
* Get a list of leaderboards.
*
* @param categoryStart - Filter leaderboard with categories greater or equal than this value.
* @param categoryEnd - Filter leaderboard with categories equal or less than this value.
* @param limit - Return only the required number of leaderboard denoted by this limit value.
* @param cursor - Cursor to paginate to the next result set. If this is empty/null there is no further results.
* @returns The leaderboard data for the given ids.
* @returns The leaderboards data.
* @throws {TypeError, GoError}
*/
leaderboardList(categoryStart?: number, categoryEnd?: number, limit?: number, cursor?: string): LeaderboardList;
Expand Down Expand Up @@ -4255,15 +4255,15 @@ declare namespace nkruntime {
tournamentsGetId(tournamentIds: string[]): Tournament[];

/**
* Get a list of tournaments by id.
* Get a list of tournaments.
*
* @param categoryStart - Filter tournament with categories greater or equal than this value.
* @param categoryEnd - Filter tournament with categories equal or less than this value.
* @param startTime - Filter tournament with that start after this time.
* @param endTime - Filter tournament with that end before this time.
* @param limit - Return only the required number of tournament denoted by this limit value.
* @param cursor - Cursor to paginate to the next result set. If this is empty/null there is no further results.
* @returns The tournament data for the given ids.
* @returns The tournaments data.
* @throws {TypeError, GoError}
*/
tournamentList(categoryStart?: number, categoryEnd?: number, startTime?: number, endTime?: number, limit?: number, cursor?: string): TournamentList;
Expand Down Expand Up @@ -4727,6 +4727,13 @@ declare namespace nkruntime {
* @throws {TypeError, GoError}
*/
localcacheDelete(key: string): void;

/**
* Get Satori object.
*
* @returns The satori integration interface.
*/
getSatori(): Satori;
}

/**
Expand All @@ -4747,4 +4754,109 @@ declare namespace nkruntime {
*/
(ctx: Context, logger: Logger, nk: Nakama, initializer: Initializer): void;
}

export interface Properties {
default: {[key: string]: string}
custom: {[key: string]: string}
computed: {[key: string]: string}
}

export interface PropertiesUpdate {
default?: {[key: string]: string}
custom?: {[key: string]: string}
}

export interface SatoriEvent {
name: string
id: string
metadata?: {[key: string]: string}
value: string
timestamp: number
}

export interface Experiment {
name: string
value: string
}

export interface Flag {
name: string
value: string
conditionChanged: boolean
}

export interface LiveEvent {
name: string
description: string
value: string
activeStartTime: number
activeEndTime: number
}

/**
* The Satori integration functions.
*/
export interface Satori {
/**
* Create identity.
*
* @param id - Identity identifier.
* @throws {TypeError, GoError}
*/
authenticate(id: string): void

/**
* Get identity properties.
*
* @param id - Identity identifier.
* @returns The identity properties.
* @throws {TypeError, GoError}
*/
propertiesGet(id: string): Properties[]

/**
* Update identity properties.
*
* @param id - Identity identifier.
* @param properties - Updated properties.
* @throws {TypeError, GoError}
*/
propertiesUpdate(id: string, properties: PropertiesUpdate): void

/**
* Publish events.
*
* @param id - Identity identifier.
* @param events - Events to publish.
* @throws {TypeError, GoError}
*/
eventsPublish(id: string, events: SatoriEvent[]): void

/**
* List experiments.
*
* @param id - Identity identifier.
* @param names - Opt. List of experiment names.
* @throws {TypeError, GoError}
*/
experimentsList(id: string, names?: string[]): Experiment[]

/**
* List flags.
*
* @param id - Identity identifier.
* @param names - Opt. List of flag names.
* @throws {TypeError, GoError}
*/
flagsList(id: string, names?: string[]): Flag[]

/**
* List live events.
*
* @param id - Identity identifier.
* @param names - Opt. List of live event names.
* @throws {TypeError, GoError}
*/
liveEventsList(id: string, names?: string[]): LiveEvent[]
}
}
4 changes: 2 additions & 2 deletions rtapi/realtime.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,4 +1132,73 @@ type NakamaModule interface {
ChannelMessageUpdate(ctx context.Context, channelID, messageID string, content map[string]interface{}, senderId, senderUsername string, persist bool) (*rtapi.ChannelMessageAck, error)
ChannelMessageRemove(ctx context.Context, channelId, messageId string, senderId, senderUsername string, persist bool) (*rtapi.ChannelMessageAck, error)
ChannelMessagesList(ctx context.Context, channelId string, limit int, forward bool, cursor string) (messages []*api.ChannelMessage, nextCursor string, prevCursor string, err error)

GetSatori() Satori
}

/*
Satori runtime integration defintions.
*/
type Satori interface {
Authenticate(ctx context.Context, id 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)
}

type Properties struct {
Default map[string]string `json:"default,omitempty"`
Custom map[string]string `json:"custom,omitempty"`
Computed map[string]string `json:"computed,omitempty"`
}

type PropertiesUpdate struct {
Default map[string]string `json:"default,omitempty"`
Custom map[string]string `json:"custom,omitempty"`
}

type Events struct {
Events []*Event
}

type Event struct {
Name string `json:"name,omitempty"`
Id string `json:"id,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Value string `json:"value,omitempty"`
Timestamp int64 `json:"-"`
}

type ExperimentList struct {
Experiments []*Experiment `json:"experiments,omitempty"`
}

type Experiment struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}

type FlagList struct {
Flags []*Flag `json:"flags,omitempty"`
}

type Flag struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
ConditionChanged bool `json:"condition_changed,omitempty"`
}

type LiveEventList struct {
LiveEvents []*LiveEvent `json:"live_events,omitempty"`
}

type LiveEvent struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Value string `json:"value,omitempty"`
ActiveStartTimeSec int64 `json:"active_start_time_sec,omitempty"`
ActiveEndTimeSec int64 `json:"active_end_time_sec,omitempty"`
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# google.golang.org/protobuf v1.28.1
## explicit
## explicit; go 1.11
google.golang.org/protobuf/cmd/protoc-gen-go
google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo
google.golang.org/protobuf/compiler/protogen
Expand Down

0 comments on commit d8dca07

Please sign in to comment.