Skip to content

Commit

Permalink
release v2.7.0 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
lugehorsam committed Sep 26, 2023
1 parent 7dece4c commit d74050d
Show file tree
Hide file tree
Showing 12 changed files with 1,006 additions and 39 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p

### Unreleased

### [2.7.0]
### Added
- Satori: Added ability to schedule, update and delete outgoing messages for Live Events.
- Satori: Added ability to add custom and default properties for a user at the point of authentication.
- Satori: Add 'recompute' param to Satori's update-properties.
- Satori: Added ability to delete identity.
- Nakama: Added ability to create match by name.

### Changed
- Nakama: Improves how outgoing messages are logged in verbose mode.
- Nakama: Updated signature for Authenticate Game Center.

### Fixed
- Nakama: Fixed typings distribution location for protobuf-js.
- Nakama: Fixed how newer bundlers (such as those used by ViteJs) discover Nakama's type definitions.
- Satori: Return live event ID when getting all live events.

### [2.6.1]

### Added
Expand Down
2 changes: 1 addition & 1 deletion openapi-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go run main.go "$GOPATH/src/github.com/heroiclabs/nakama/apigrpc/apigrpc.swagger
### Satori

```shell
go run main.go "$GOPATH/src/github.com/heroiclabs/nakama/apigrpc/apigrpc.swagger.json" "Satori" > ../packages/satori-js/api.gen.ts
go run main.go "$GOPATH/src/github.com/heroiclabs/satori/api/satori.swagger.json" "Satori" > ../packages/satori-js/api.gen.ts
```

### Rationale
Expand Down
2 changes: 1 addition & 1 deletion packages/nakama-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@heroiclabs/nakama-js",
"version": "2.6.1",
"version": "2.7.0",
"scripts": {
"build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"
},
Expand Down
166 changes: 165 additions & 1 deletion packages/satori-js/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export interface ApiAuthenticateRefreshRequest {

/** */
export interface ApiAuthenticateRequest {
//Optional custom properties to update with this call. If not set, properties are left as they are on the server.
custom?: Record<string, string>;
//Optional default properties to update with this call. If not set, properties are left as they are on the server.
default?: Record<string, string>;
//Identity ID. Must be between eight and 128 characters (inclusive). Must be an alphanumeric string with only underscores and hyphens allowed.
id?: string;
}
Expand Down Expand Up @@ -74,6 +78,18 @@ export interface ApiFlagList {
flags?: Array<ApiFlag>;
}

/** A response containing all the messages for an identity. */
export interface ApiGetMessageListResponse {
//Cacheable cursor to list newer messages. Durable and designed to be stored, unlike next/prev cursors.
cacheable_cursor?: string;
//The list of messages.
messages?: Array<ApiMessage>;
//The cursor to send when retrieving the next page, if any.
next_cursor?: string;
//The cursor to send when retrieving the previous page, if any.
prev_cursor?: string;
}

/** Enrich/replace the current session with a new ID. */
export interface ApiIdentifyRequest {
//Optional custom properties to update with this call. If not set, properties are left as they are on the server.
Expand All @@ -92,6 +108,8 @@ export interface ApiLiveEvent {
active_start_time_sec?: string;
//Description.
description?: string;
//The live event identifier.
id?: string;
//Name.
name?: string;
//Event value.
Expand All @@ -104,6 +122,26 @@ export interface ApiLiveEventList {
live_events?: Array<ApiLiveEvent>;
}

/** A scheduled message. */
export interface ApiMessage {
//The time the message was consumed by the identity.
consume_time?: string;
//The time the message was created.
create_time?: string;
//A key-value pairs of metadata.
metadata?: Record<string, string>;
//The time the message was read by the client.
read_time?: string;
//The identifier of the schedule.
schedule_id?: string;
//The send time for the message.
send_time?: string;
//The message's text.
text?: string;
//The time the message was updated.
update_time?: string;
}

/** Properties associated with an identity. */
export interface ApiProperties {
//Event computed properties.
Expand All @@ -124,6 +162,16 @@ export interface ApiSession {
token?: string;
}

/** The request to update the status of a message. */
export interface ApiUpdateMessageRequest {
//The time the message was consumed by the identity.
consume_time?: string;
//The identifier of the messages.
id?: string;
//The time the message was read at the client.
read_time?: string;
}

/** Update Properties associated with this identity. */
export interface ApiUpdatePropertiesRequest {
//Event custom properties.
Expand All @@ -137,7 +185,9 @@ export interface ApiUpdatePropertiesRequest {
/** */
export interface ProtobufAny {
//
type?: string;
type_url?: string;
//
value?: string;
}

/** */
Expand Down Expand Up @@ -532,6 +582,120 @@ export class SatoriApi {
]);
}

/** Get the list of messages for the identity. */
satoriGetMessageList(bearerToken: string,
limit?:number,
forward?:boolean,
cursor?:string,
options: any = {}): Promise<ApiGetMessageListResponse> {

const urlPath = "/v1/message";
const queryParams = new Map<string, any>();
queryParams.set("limit", limit);
queryParams.set("forward", forward);
queryParams.set("cursor", cursor);

let bodyJson : string = "";

const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
const fetchOptions = buildFetchOptions("GET", options, bodyJson);
if (bearerToken) {
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
}

return Promise.race([
fetch(fullUrl, fetchOptions).then((response) => {
if (response.status == 204) {
return response;
} else if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
throw response;
}
}),
new Promise((_, reject) =>
setTimeout(reject, this.timeoutMs, "Request timed out.")
),
]);
}

/** Deletes a message for an identity. */
satoriDeleteMessage(bearerToken: string,
id:string,
options: any = {}): Promise<any> {

if (id === null || id === undefined) {
throw new Error("'id' is a required parameter but is null or undefined.");
}
const urlPath = "/v1/message/{id}"
.replace("{id}", encodeURIComponent(String(id)));
const queryParams = new Map<string, any>();

let bodyJson : string = "";

const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
const fetchOptions = buildFetchOptions("DELETE", options, bodyJson);
if (bearerToken) {
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
}

return Promise.race([
fetch(fullUrl, fetchOptions).then((response) => {
if (response.status == 204) {
return response;
} else if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
throw response;
}
}),
new Promise((_, reject) =>
setTimeout(reject, this.timeoutMs, "Request timed out.")
),
]);
}

/** Updates a message for an identity. */
satoriUpdateMessage(bearerToken: string,
id:string,
body:ApiUpdateMessageRequest,
options: any = {}): Promise<any> {

if (id === null || id === undefined) {
throw new Error("'id' is a required parameter but is null or undefined.");
}
if (body === null || body === undefined) {
throw new Error("'body' is a required parameter but is null or undefined.");
}
const urlPath = "/v1/message/{id}"
.replace("{id}", encodeURIComponent(String(id)));
const queryParams = new Map<string, any>();

let bodyJson : string = "";
bodyJson = JSON.stringify(body || {});

const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
if (bearerToken) {
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
}

return Promise.race([
fetch(fullUrl, fetchOptions).then((response) => {
if (response.status == 204) {
return response;
} else if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
throw response;
}
}),
new Promise((_, reject) =>
setTimeout(reject, this.timeoutMs, "Request timed out.")
),
]);
}

/** List properties associated with this identity. */
satoriListProperties(bearerToken: string,
options: any = {}): Promise<ApiProperties> {
Expand Down
49 changes: 45 additions & 4 deletions packages/satori-js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { SatoriApi, ApiSession, ApiAuthenticateRequest, ApiEventRequest, ApiAuthenticateLogoutRequest, ApiAuthenticateRefreshRequest, ApiIdentifyRequest, ApiUpdatePropertiesRequest, ApiEvent } from "./api.gen";
import { SatoriApi, ApiSession, ApiAuthenticateRequest, ApiEventRequest, ApiAuthenticateLogoutRequest, ApiAuthenticateRefreshRequest, ApiIdentifyRequest, ApiUpdatePropertiesRequest, ApiEvent, ApiUpdateMessageRequest } from "./api.gen";

import { Session } from "./session";

Expand Down Expand Up @@ -47,10 +47,12 @@ export class Client {
}

/** Authenticate a user with an ID against the server. */
async authenticate(id: string) {
async authenticate(id: string, customProperties?: Record<string, string>, defaultProperties?: Record<string, string>) {

const request : ApiAuthenticateRequest = {
"id": id,
custom: customProperties,
default: defaultProperties
};

return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession : ApiSession) => {
Expand Down Expand Up @@ -149,7 +151,7 @@ export class Client {
});
}


/** Get a single flag for this identity. */
async getFlagWithFallback(session: Session, name: string, fallbackValue?: string) {
return this.getFlag(session, name)
Expand Down Expand Up @@ -278,9 +280,48 @@ export class Client {
session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
await this.sessionRefresh(session);
}

return this.apiClient.satoriDeleteIdentity(session.token).then((response) => {
return Promise.resolve(response !== undefined);
});
}

async getMessageList(session : Session) {
if (this.autoRefreshSession && session.refresh_token &&
session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
await this.sessionRefresh(session);
}

return this.apiClient.satoriGetMessageList(session.token).then((response) => {
return Promise.resolve(response !== undefined);
});
}

async deleteMessage(session : Session, id : string) {
if (this.autoRefreshSession && session.refresh_token &&
session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
await this.sessionRefresh(session);
}

return this.apiClient.satoriDeleteMessage(session.token, id).then((response) => {
return Promise.resolve(response !== undefined);
});
}

async updateMessage(session : Session, id : string, consume_time? : string, read_time? : string) {
if (this.autoRefreshSession && session.refresh_token &&
session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
await this.sessionRefresh(session);
}

const request : ApiUpdateMessageRequest = {
id: id,
consume_time: consume_time,
read_time: read_time
};

return this.apiClient.satoriUpdateMessage(session.token, id, request).then((response) => {
return Promise.resolve(response !== undefined);
});
}
};
Loading

0 comments on commit d74050d

Please sign in to comment.