diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a31a1..7a4578d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/openapi-gen/README.md b/openapi-gen/README.md index 4c7e7f6..d0718dc 100644 --- a/openapi-gen/README.md +++ b/openapi-gen/README.md @@ -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 diff --git a/packages/nakama-js/package.json b/packages/nakama-js/package.json index f384c43..2fe55f8 100644 --- a/packages/nakama-js/package.json +++ b/packages/nakama-js/package.json @@ -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" }, diff --git a/packages/satori-js/api.gen.ts b/packages/satori-js/api.gen.ts index e044f9f..a172c17 100644 --- a/packages/satori-js/api.gen.ts +++ b/packages/satori-js/api.gen.ts @@ -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; + //Optional default properties to update with this call. If not set, properties are left as they are on the server. + default?: Record; //Identity ID. Must be between eight and 128 characters (inclusive). Must be an alphanumeric string with only underscores and hyphens allowed. id?: string; } @@ -74,6 +78,18 @@ export interface ApiFlagList { flags?: Array; } +/** 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; + //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. @@ -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. @@ -104,6 +122,26 @@ export interface ApiLiveEventList { live_events?: Array; } +/** 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; + //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. @@ -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. @@ -137,7 +185,9 @@ export interface ApiUpdatePropertiesRequest { /** */ export interface ProtobufAny { // - type?: string; + type_url?: string; + // + value?: string; } /** */ @@ -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 { + + const urlPath = "/v1/message"; + const queryParams = new Map(); + 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 { + + 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(); + + 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 { + + 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(); + + 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 { diff --git a/packages/satori-js/client.ts b/packages/satori-js/client.ts index 74f6558..97f2b7f 100644 --- a/packages/satori-js/client.ts +++ b/packages/satori-js/client.ts @@ -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"; @@ -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, defaultProperties?: Record) { const request : ApiAuthenticateRequest = { "id": id, + custom: customProperties, + default: defaultProperties }; return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession : ApiSession) => { @@ -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) @@ -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); + }); + } }; diff --git a/packages/satori-js/dist/api.gen.d.ts b/packages/satori-js/dist/api.gen.d.ts index b54f159..9aba897 100644 --- a/packages/satori-js/dist/api.gen.d.ts +++ b/packages/satori-js/dist/api.gen.d.ts @@ -9,6 +9,8 @@ export interface ApiAuthenticateRefreshRequest { } /** */ export interface ApiAuthenticateRequest { + custom?: Record; + default?: Record; id?: string; } /** A single event. Usually, but not necessarily, part of a batch. */ @@ -42,6 +44,13 @@ export interface ApiFlag { export interface ApiFlagList { flags?: Array; } +/** A response containing all the messages for an identity. */ +export interface ApiGetMessageListResponse { + cacheable_cursor?: string; + messages?: Array; + next_cursor?: string; + prev_cursor?: string; +} /** Enrich/replace the current session with a new ID. */ export interface ApiIdentifyRequest { custom?: Record; @@ -53,6 +62,7 @@ export interface ApiLiveEvent { active_end_time_sec?: string; active_start_time_sec?: string; description?: string; + id?: string; name?: string; value?: string; } @@ -60,6 +70,17 @@ export interface ApiLiveEvent { export interface ApiLiveEventList { live_events?: Array; } +/** A scheduled message. */ +export interface ApiMessage { + consume_time?: string; + create_time?: string; + metadata?: Record; + read_time?: string; + schedule_id?: string; + send_time?: string; + text?: string; + update_time?: string; +} /** Properties associated with an identity. */ export interface ApiProperties { computed?: Record; @@ -72,14 +93,22 @@ export interface ApiSession { refresh_token?: string; token?: string; } +/** The request to update the status of a message. */ +export interface ApiUpdateMessageRequest { + consume_time?: string; + id?: string; + read_time?: string; +} /** Update Properties associated with this identity. */ export interface ApiUpdatePropertiesRequest { custom?: Record; default?: Record; + recompute?: boolean; } /** */ export interface ProtobufAny { - type?: string; + type_url?: string; + value?: string; } /** */ export interface RpcStatus { @@ -110,8 +139,16 @@ export declare class SatoriApi { satoriGetFlags(bearerToken: string, basicAuthUsername: string, basicAuthPassword: string, names?: Array, options?: any): Promise; /** Enrich/replace the current session with new identifier. */ satoriIdentify(bearerToken: string, body: ApiIdentifyRequest, options?: any): Promise; + /** Delete the caller's identity and associated data. */ + satoriDeleteIdentity(bearerToken: string, options?: any): Promise; /** List available live events. */ satoriGetLiveEvents(bearerToken: string, names?: Array, options?: any): Promise; + /** Get the list of messages for the identity. */ + satoriGetMessageList(bearerToken: string, limit?: number, forward?: boolean, cursor?: string, options?: any): Promise; + /** Deletes a message for an identity. */ + satoriDeleteMessage(bearerToken: string, id: string, options?: any): Promise; + /** Updates a message for an identity. */ + satoriUpdateMessage(bearerToken: string, id: string, body: ApiUpdateMessageRequest, options?: any): Promise; /** List properties associated with this identity. */ satoriListProperties(bearerToken: string, options?: any): Promise; /** Update identity properties. */ diff --git a/packages/satori-js/dist/client.d.ts b/packages/satori-js/dist/client.d.ts index 3b2decb..c06f815 100644 --- a/packages/satori-js/dist/client.d.ts +++ b/packages/satori-js/dist/client.d.ts @@ -29,7 +29,7 @@ export declare class Client { private readonly apiClient; constructor(apiKey?: string, host?: string, port?: string, useSSL?: boolean, timeout?: number, autoRefreshSession?: boolean); /** Authenticate a user with an ID against the server. */ - authenticate(id: string): Promise; + authenticate(id: string, customProperties?: Record, defaultProperties?: Record): Promise; /** Refresh a user's session using a refresh token retrieved from a previous authentication request. */ sessionRefresh(session: Session): Promise; /** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */ @@ -65,5 +65,10 @@ export declare class Client { /** List properties associated with this identity. */ listProperties(session: Session): Promise; /** Update identity properties. */ - updateProperties(session: Session, defaultProperties?: Record, customProperties?: Record): Promise; + updateProperties(session: Session, defaultProperties?: Record, customProperties?: Record, recompute?: boolean): Promise; + /** Delete the caller's identity and associated data. */ + deleteIdentity(session: Session): Promise; + getMessageList(session: Session): Promise; + deleteMessage(session: Session, id: string): Promise; + updateMessage(session: Session, id: string, consume_time?: string, read_time?: string): Promise; } diff --git a/packages/satori-js/dist/satori-js.cjs.js b/packages/satori-js/dist/satori-js.cjs.js index 2385791..62c3eaa 100644 --- a/packages/satori-js/dist/satori-js.cjs.js +++ b/packages/satori-js/dist/satori-js.cjs.js @@ -377,10 +377,10 @@ function Request(input, options) { if (options.cache === "no-store" || options.cache === "no-cache") { var reParamSearch = /([?&])_=[^&]*/; if (reParamSearch.test(this.url)) { - this.url = this.url.replace(reParamSearch, "$1_=" + new Date().getTime()); + this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime()); } else { var reQueryString = /\?/; - this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + new Date().getTime(); + this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime(); } } } @@ -565,7 +565,7 @@ var b64tab = ((a) => { })(b64chs); var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; var _fromCC = String.fromCharCode.bind(String); -var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn)); +var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0)); var _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_"); var _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, ""); var btoaPolyfill = (bin) => { @@ -897,6 +897,31 @@ var SatoriApi = class { ) ]); } + /** Delete the caller's identity and associated data. */ + satoriDeleteIdentity(bearerToken, options = {}) { + const urlPath = "/v1/identity"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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.") + ) + ]); + } /** List available live events. */ satoriGetLiveEvents(bearerToken, names, options = {}) { const urlPath = "/v1/live-event"; @@ -923,6 +948,94 @@ var SatoriApi = class { ) ]); } + /** Get the list of messages for the identity. */ + satoriGetMessageList(bearerToken, limit, forward, cursor, options = {}) { + const urlPath = "/v1/message"; + const queryParams = /* @__PURE__ */ new Map(); + queryParams.set("limit", limit); + queryParams.set("forward", forward); + queryParams.set("cursor", cursor); + let bodyJson = ""; + 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, id, options = {}) { + if (id === null || id === void 0) { + 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 = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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, id, body, options = {}) { + if (id === null || id === void 0) { + throw new Error("'id' is a required parameter but is null or undefined."); + } + if (body === null || body === void 0) { + 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 = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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, options = {}) { const urlPath = "/v1/properties"; @@ -999,7 +1112,7 @@ var Session = class { constructor(token, refresh_token) { this.token = token; this.refresh_token = refresh_token; - this.created_at = Math.floor(new Date().getTime() / 1e3); + this.created_at = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3); this.update(token, refresh_token); } isexpired(currenttime) { @@ -1056,10 +1169,12 @@ var Client = class { this.apiClient = new SatoriApi(apiKey, basePath, timeout); } /** Authenticate a user with an ID against the server. */ - authenticate(id) { + authenticate(id, customProperties, defaultProperties) { return __async(this, null, function* () { const request = { - "id": id + "id": id, + custom: customProperties, + default: defaultProperties }; return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession) => { return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || "")); @@ -1243,18 +1358,65 @@ var Client = class { }); } /** Update identity properties. */ - updateProperties(session, defaultProperties, customProperties) { + updateProperties(session, defaultProperties, customProperties, recompute) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } const request = { default: defaultProperties, - custom: customProperties + custom: customProperties, + recompute }; return this.apiClient.satoriUpdateProperties(session.token, request).then((response) => { return Promise.resolve(response !== void 0); }); }); } + /** Delete the caller's identity and associated data. */ + deleteIdentity(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriDeleteIdentity(session.token).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + getMessageList(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriGetMessageList(session.token).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + deleteMessage(session, id) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriDeleteMessage(session.token, id).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + updateMessage(session, id, consume_time, read_time) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + const request = { + id, + consume_time, + read_time + }; + return this.apiClient.satoriUpdateMessage(session.token, id, request).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } }; diff --git a/packages/satori-js/dist/satori-js.esm.mjs b/packages/satori-js/dist/satori-js.esm.mjs index 5d98cd1..9519e6e 100644 --- a/packages/satori-js/dist/satori-js.esm.mjs +++ b/packages/satori-js/dist/satori-js.esm.mjs @@ -353,10 +353,10 @@ function Request(input, options) { if (options.cache === "no-store" || options.cache === "no-cache") { var reParamSearch = /([?&])_=[^&]*/; if (reParamSearch.test(this.url)) { - this.url = this.url.replace(reParamSearch, "$1_=" + new Date().getTime()); + this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime()); } else { var reQueryString = /\?/; - this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + new Date().getTime(); + this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime(); } } } @@ -541,7 +541,7 @@ var b64tab = ((a) => { })(b64chs); var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; var _fromCC = String.fromCharCode.bind(String); -var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn)); +var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0)); var _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_"); var _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, ""); var btoaPolyfill = (bin) => { @@ -873,6 +873,31 @@ var SatoriApi = class { ) ]); } + /** Delete the caller's identity and associated data. */ + satoriDeleteIdentity(bearerToken, options = {}) { + const urlPath = "/v1/identity"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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.") + ) + ]); + } /** List available live events. */ satoriGetLiveEvents(bearerToken, names, options = {}) { const urlPath = "/v1/live-event"; @@ -899,6 +924,94 @@ var SatoriApi = class { ) ]); } + /** Get the list of messages for the identity. */ + satoriGetMessageList(bearerToken, limit, forward, cursor, options = {}) { + const urlPath = "/v1/message"; + const queryParams = /* @__PURE__ */ new Map(); + queryParams.set("limit", limit); + queryParams.set("forward", forward); + queryParams.set("cursor", cursor); + let bodyJson = ""; + 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, id, options = {}) { + if (id === null || id === void 0) { + 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 = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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, id, body, options = {}) { + if (id === null || id === void 0) { + throw new Error("'id' is a required parameter but is null or undefined."); + } + if (body === null || body === void 0) { + 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 = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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, options = {}) { const urlPath = "/v1/properties"; @@ -975,7 +1088,7 @@ var Session = class { constructor(token, refresh_token) { this.token = token; this.refresh_token = refresh_token; - this.created_at = Math.floor(new Date().getTime() / 1e3); + this.created_at = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3); this.update(token, refresh_token); } isexpired(currenttime) { @@ -1032,10 +1145,12 @@ var Client = class { this.apiClient = new SatoriApi(apiKey, basePath, timeout); } /** Authenticate a user with an ID against the server. */ - authenticate(id) { + authenticate(id, customProperties, defaultProperties) { return __async(this, null, function* () { const request = { - "id": id + "id": id, + custom: customProperties, + default: defaultProperties }; return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession) => { return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || "")); @@ -1219,20 +1334,67 @@ var Client = class { }); } /** Update identity properties. */ - updateProperties(session, defaultProperties, customProperties) { + updateProperties(session, defaultProperties, customProperties, recompute) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } const request = { default: defaultProperties, - custom: customProperties + custom: customProperties, + recompute }; return this.apiClient.satoriUpdateProperties(session.token, request).then((response) => { return Promise.resolve(response !== void 0); }); }); } + /** Delete the caller's identity and associated data. */ + deleteIdentity(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriDeleteIdentity(session.token).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + getMessageList(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriGetMessageList(session.token).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + deleteMessage(session, id) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriDeleteMessage(session.token, id).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + updateMessage(session, id, consume_time, read_time) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + const request = { + id, + consume_time, + read_time + }; + return this.apiClient.satoriUpdateMessage(session.token, id, request).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } }; export { Client, diff --git a/packages/satori-js/dist/satori-js.iife.js b/packages/satori-js/dist/satori-js.iife.js index bded3cc..4aa84cf 100644 --- a/packages/satori-js/dist/satori-js.iife.js +++ b/packages/satori-js/dist/satori-js.iife.js @@ -377,10 +377,10 @@ var satorijs = (() => { if (options.cache === "no-store" || options.cache === "no-cache") { var reParamSearch = /([?&])_=[^&]*/; if (reParamSearch.test(this.url)) { - this.url = this.url.replace(reParamSearch, "$1_=" + new Date().getTime()); + this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime()); } else { var reQueryString = /\?/; - this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + new Date().getTime(); + this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime(); } } } @@ -565,7 +565,7 @@ var satorijs = (() => { })(b64chs); var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; var _fromCC = String.fromCharCode.bind(String); - var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn)); + var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : (it) => new Uint8Array(Array.prototype.slice.call(it, 0)); var _mkUriSafe = (src) => src.replace(/=/g, "").replace(/[+\/]/g, (m0) => m0 == "+" ? "-" : "_"); var _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, ""); var btoaPolyfill = (bin) => { @@ -897,6 +897,31 @@ var satorijs = (() => { ) ]); } + /** Delete the caller's identity and associated data. */ + satoriDeleteIdentity(bearerToken, options = {}) { + const urlPath = "/v1/identity"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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.") + ) + ]); + } /** List available live events. */ satoriGetLiveEvents(bearerToken, names, options = {}) { const urlPath = "/v1/live-event"; @@ -923,6 +948,94 @@ var satorijs = (() => { ) ]); } + /** Get the list of messages for the identity. */ + satoriGetMessageList(bearerToken, limit, forward, cursor, options = {}) { + const urlPath = "/v1/message"; + const queryParams = /* @__PURE__ */ new Map(); + queryParams.set("limit", limit); + queryParams.set("forward", forward); + queryParams.set("cursor", cursor); + let bodyJson = ""; + 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, id, options = {}) { + if (id === null || id === void 0) { + 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 = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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, id, body, options = {}) { + if (id === null || id === void 0) { + throw new Error("'id' is a required parameter but is null or undefined."); + } + if (body === null || body === void 0) { + 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 = /* @__PURE__ */ new Map(); + let bodyJson = ""; + 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, options = {}) { const urlPath = "/v1/properties"; @@ -999,7 +1112,7 @@ var satorijs = (() => { constructor(token, refresh_token) { this.token = token; this.refresh_token = refresh_token; - this.created_at = Math.floor(new Date().getTime() / 1e3); + this.created_at = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3); this.update(token, refresh_token); } isexpired(currenttime) { @@ -1056,10 +1169,12 @@ var satorijs = (() => { this.apiClient = new SatoriApi(apiKey, basePath, timeout); } /** Authenticate a user with an ID against the server. */ - authenticate(id) { + authenticate(id, customProperties, defaultProperties) { return __async(this, null, function* () { const request = { - "id": id + "id": id, + custom: customProperties, + default: defaultProperties }; return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession) => { return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || "")); @@ -1243,20 +1358,67 @@ var satorijs = (() => { }); } /** Update identity properties. */ - updateProperties(session, defaultProperties, customProperties) { + updateProperties(session, defaultProperties, customProperties, recompute) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } const request = { default: defaultProperties, - custom: customProperties + custom: customProperties, + recompute }; return this.apiClient.satoriUpdateProperties(session.token, request).then((response) => { return Promise.resolve(response !== void 0); }); }); } + /** Delete the caller's identity and associated data. */ + deleteIdentity(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriDeleteIdentity(session.token).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + getMessageList(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriGetMessageList(session.token).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + deleteMessage(session, id) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.satoriDeleteMessage(session.token, id).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } + updateMessage(session, id, consume_time, read_time) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + const request = { + id, + consume_time, + read_time + }; + return this.apiClient.satoriUpdateMessage(session.token, id, request).then((response) => { + return Promise.resolve(response !== void 0); + }); + }); + } }; return __toCommonJS(satori_js_exports); })(); diff --git a/packages/satori-js/dist/satori-js.umd.js b/packages/satori-js/dist/satori-js.umd.js index 2fc3d55..f3d440a 100644 --- a/packages/satori-js/dist/satori-js.umd.js +++ b/packages/satori-js/dist/satori-js.umd.js @@ -624,6 +624,8 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ + /* global Reflect, Promise */ + var __assign = function() { __assign = Object.assign || function __assign(t) { @@ -730,7 +732,7 @@ const _fromCC = String.fromCharCode.bind(String); typeof Uint8Array.from === 'function' ? Uint8Array.from.bind(Uint8Array) - : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn)); + : (it) => new Uint8Array(Array.prototype.slice.call(it, 0)); const _mkUriSafe = (src) => src .replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_'); const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, ''); @@ -874,6 +876,7 @@ } // tslint:disable + /* Code generated by openapi-gen/main.go. DO NOT EDIT. */ var SatoriApi = /** @class */ (function () { function SatoriApi(apiKey, basePath, timeoutMs) { this.apiKey = apiKey; @@ -1166,6 +1169,35 @@ }), ]); }; + /** Delete the caller's identity and associated data. */ + SatoriApi.prototype.satoriDeleteIdentity = function (bearerToken, options) { + var _this = this; + if (options === void 0) { options = {}; } + var urlPath = "/v1/identity"; + var queryParams = new Map(); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** List available live events. */ SatoriApi.prototype.satoriGetLiveEvents = function (bearerToken, names, options) { var _this = this; @@ -1196,6 +1228,108 @@ }), ]); }; + /** Get the list of messages for the identity. */ + SatoriApi.prototype.satoriGetMessageList = function (bearerToken, limit, forward, cursor, options) { + var _this = this; + if (options === void 0) { options = {}; } + var urlPath = "/v1/message"; + var queryParams = new Map(); + queryParams.set("limit", limit); + queryParams.set("forward", forward); + queryParams.set("cursor", cursor); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; + /** Deletes a message for an identity. */ + SatoriApi.prototype.satoriDeleteMessage = function (bearerToken, id, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (id === null || id === undefined) { + throw new Error("'id' is a required parameter but is null or undefined."); + } + var urlPath = "/v1/message/{id}" + .replace("{id}", encodeURIComponent(String(id))); + var queryParams = new Map(); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; + /** Updates a message for an identity. */ + SatoriApi.prototype.satoriUpdateMessage = function (bearerToken, id, body, options) { + var _this = this; + if (options === void 0) { options = {}; } + 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."); + } + var urlPath = "/v1/message/{id}" + .replace("{id}", encodeURIComponent(String(id))); + var queryParams = new Map(); + var bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("PUT", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** List properties associated with this identity. */ SatoriApi.prototype.satoriListProperties = function (bearerToken, options) { var _this = this; @@ -1391,12 +1525,14 @@ this.apiClient = new SatoriApi(apiKey, basePath, timeout); } /** Authenticate a user with an ID against the server. */ - Client.prototype.authenticate = function (id) { + Client.prototype.authenticate = function (id, customProperties, defaultProperties) { return __awaiter(this, void 0, void 0, function () { var request; return __generator(this, function (_a) { request = { "id": id, + custom: customProperties, + default: defaultProperties }; return [2 /*return*/, this.apiClient.satoriAuthenticate(this.apiKey, "", request).then(function (apiSession) { return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || "")); @@ -1669,7 +1805,7 @@ }); }; /** Update identity properties. */ - Client.prototype.updateProperties = function (session, defaultProperties, customProperties) { + Client.prototype.updateProperties = function (session, defaultProperties, customProperties, recompute) { return __awaiter(this, void 0, void 0, function () { var request; return __generator(this, function (_a) { @@ -1684,7 +1820,8 @@ case 2: request = { default: defaultProperties, - custom: customProperties + custom: customProperties, + recompute: recompute, }; return [2 /*return*/, this.apiClient.satoriUpdateProperties(session.token, request).then(function (response) { return Promise.resolve(response !== undefined); @@ -1693,6 +1830,86 @@ }); }); }; + /** Delete the caller's identity and associated data. */ + Client.prototype.deleteIdentity = function (session) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.satoriDeleteIdentity(session.token).then(function (response) { + return Promise.resolve(response !== undefined); + })]; + } + }); + }); + }; + Client.prototype.getMessageList = function (session) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.satoriGetMessageList(session.token).then(function (response) { + return Promise.resolve(response !== undefined); + })]; + } + }); + }); + }; + Client.prototype.deleteMessage = function (session, id) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.satoriDeleteMessage(session.token, id).then(function (response) { + return Promise.resolve(response !== undefined); + })]; + } + }); + }); + }; + Client.prototype.updateMessage = function (session, id, consume_time, read_time) { + return __awaiter(this, void 0, void 0, function () { + var request; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + request = { + id: id, + consume_time: consume_time, + read_time: read_time + }; + return [2 /*return*/, this.apiClient.satoriUpdateMessage(session.token, id, request).then(function (response) { + return Promise.resolve(response !== undefined); + })]; + } + }); + }); + }; return Client; }()); diff --git a/packages/satori-js/package.json b/packages/satori-js/package.json index d6dbf3e..aaa8ef6 100644 --- a/packages/satori-js/package.json +++ b/packages/satori-js/package.json @@ -1,6 +1,6 @@ { "name": "@heroiclabs/satori-js", - "version": "2.5.3", + "version": "2.7.0", "scripts": { "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs", "docs": "typedoc index.ts --gaID UA-89839802-1 --out ../../docs"