@rtsdk/topia 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__mocks__/worlds.js +1 -0
- package/dist/controllers/Asset.js +2 -44
- package/dist/controllers/DroppedAsset.js +36 -35
- package/dist/controllers/User.js +63 -0
- package/dist/controllers/Visitor.js +4 -43
- package/dist/controllers/World.js +112 -63
- package/dist/controllers/__tests__/asset.test.js +13 -4
- package/dist/controllers/__tests__/droppedAsset.test.js +55 -71
- package/dist/controllers/__tests__/user.test.js +23 -0
- package/dist/controllers/__tests__/visitor.test.js +17 -5
- package/dist/controllers/__tests__/world.test.js +49 -24
- package/dist/controllers/index.js +1 -1
- package/dist/index.js +229 -214
- package/dist/{types/DroppedAssetType.js → interfaces/AssetInterfaces.js} +0 -0
- package/dist/{types/VisitorType.js → interfaces/VisitorInterfaces.js} +0 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/utils/__tests__/removeUndefined.test.js +10 -0
- package/dist/utils/__tests__/scatterVisitors.test.js +4 -4
- package/dist/utils/getErrorMessage.js +2 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/publicAPI.js +0 -1
- package/dist/utils/removeUndefined.js +8 -0
- package/package.json +1 -1
- package/dist/controllers/Scene.js +0 -22
- package/dist/controllers/__tests__/scene.test.js +0 -14
- package/dist/types/Visitors.js +0 -1
- package/dist/utils/createVisitor.js +0 -3
package/dist/index.js
CHANGED
|
@@ -11,13 +11,9 @@ import require$$0$2 from 'os';
|
|
|
11
11
|
import zlib from 'zlib';
|
|
12
12
|
import EventEmitter from 'events';
|
|
13
13
|
|
|
14
|
-
const createVisitor = (Visitor, apiKey, data, urlSlug) => {
|
|
15
|
-
return new Visitor(apiKey, data.color, data.displayName, data.gestureType, data.hidden, data.isAdmin, data.isBackground, data.isMobile, data.isRecording, data.isRecordingBot, data.lastUpdate, data.moveFrom, data.movedOn, data.moveTo, data.muted, data.performer, data.performerNear, data.playerId, data.shareScreen, data.sitting, urlSlug, data.username);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
14
|
const getErrorMessage = (error) => {
|
|
19
|
-
|
|
20
|
-
const errorMessage = error
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
const errorMessage = (_c = (_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errors[0]) === null || _c === void 0 ? void 0 : _c.message;
|
|
21
17
|
return errorMessage || "Something went wrong. Please try again or contact support.";
|
|
22
18
|
};
|
|
23
19
|
|
|
@@ -17825,13 +17821,21 @@ const publicAPI = (apiKey) => {
|
|
|
17825
17821
|
return axios.create({
|
|
17826
17822
|
baseURL: "https://api.topia.io/api",
|
|
17827
17823
|
headers: {
|
|
17828
|
-
"Accept-Encoding": "",
|
|
17829
17824
|
"Authorization": apiKey,
|
|
17830
17825
|
"Content-Type": "application/json",
|
|
17831
17826
|
},
|
|
17832
17827
|
});
|
|
17833
17828
|
};
|
|
17834
17829
|
|
|
17830
|
+
const removeUndefined = (obj) => {
|
|
17831
|
+
Object.keys(obj).forEach((key) => {
|
|
17832
|
+
if (obj[key] === undefined) {
|
|
17833
|
+
delete obj[key];
|
|
17834
|
+
}
|
|
17835
|
+
});
|
|
17836
|
+
return obj;
|
|
17837
|
+
};
|
|
17838
|
+
|
|
17835
17839
|
const scatterVisitors = (original, scatterBy) => {
|
|
17836
17840
|
const min = original - scatterBy;
|
|
17837
17841
|
const max = original + scatterBy;
|
|
@@ -17839,51 +17843,9 @@ const scatterVisitors = (original, scatterBy) => {
|
|
|
17839
17843
|
};
|
|
17840
17844
|
|
|
17841
17845
|
class Asset {
|
|
17842
|
-
|
|
17843
|
-
apiKey;
|
|
17844
|
-
assetName;
|
|
17845
|
-
creatorTags;
|
|
17846
|
-
id;
|
|
17847
|
-
isPublic;
|
|
17848
|
-
kitId;
|
|
17849
|
-
layer0;
|
|
17850
|
-
layer1;
|
|
17851
|
-
library;
|
|
17852
|
-
originalAssetId;
|
|
17853
|
-
originalKit;
|
|
17854
|
-
ownerId;
|
|
17855
|
-
ownerName;
|
|
17856
|
-
platformAsset;
|
|
17857
|
-
purchased;
|
|
17858
|
-
purchaseDate;
|
|
17859
|
-
purchasedFrom;
|
|
17860
|
-
specialType;
|
|
17861
|
-
transactionId;
|
|
17862
|
-
type;
|
|
17863
|
-
urlSlug;
|
|
17864
|
-
constructor(addedOn = "", apiKey, assetName = "", creatorTags = {}, id = "", isPublic = false, kitId = "", layer0 = "", layer1 = "", library = "", originalAssetId = "", originalKit = "", ownerId = "", ownerName = "", platformAsset = false, purchased = false, purchaseDate = "", purchasedFrom = "", specialType = "", transactionId = "", type = "", urlSlug = "") {
|
|
17865
|
-
this.addedOn = addedOn;
|
|
17846
|
+
constructor({ apiKey, args }) {
|
|
17866
17847
|
this.apiKey = apiKey;
|
|
17867
|
-
this
|
|
17868
|
-
this.creatorTags = creatorTags;
|
|
17869
|
-
this.id = id;
|
|
17870
|
-
this.isPublic = isPublic;
|
|
17871
|
-
this.kitId = kitId;
|
|
17872
|
-
this.layer0 = layer0;
|
|
17873
|
-
this.layer1 = layer1;
|
|
17874
|
-
this.library = library;
|
|
17875
|
-
this.originalAssetId = originalAssetId;
|
|
17876
|
-
this.originalKit = originalKit;
|
|
17877
|
-
this.ownerId = ownerId;
|
|
17878
|
-
this.ownerName = ownerName;
|
|
17879
|
-
this.platformAsset = platformAsset;
|
|
17880
|
-
this.purchased = purchased;
|
|
17881
|
-
this.purchaseDate = purchaseDate;
|
|
17882
|
-
this.purchasedFrom = purchasedFrom;
|
|
17883
|
-
this.specialType = specialType;
|
|
17884
|
-
this.transactionId = transactionId;
|
|
17885
|
-
this.type = type;
|
|
17886
|
-
this.urlSlug = urlSlug;
|
|
17848
|
+
Object.assign(this, args);
|
|
17887
17849
|
}
|
|
17888
17850
|
fetchAssetsByEmail(ownerEmail) {
|
|
17889
17851
|
return new Promise((resolve, reject) => {
|
|
@@ -17899,17 +17861,66 @@ class Asset {
|
|
|
17899
17861
|
}
|
|
17900
17862
|
}
|
|
17901
17863
|
|
|
17864
|
+
/******************************************************************************
|
|
17865
|
+
Copyright (c) Microsoft Corporation.
|
|
17866
|
+
|
|
17867
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
17868
|
+
purpose with or without fee is hereby granted.
|
|
17869
|
+
|
|
17870
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17871
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
17872
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17873
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17874
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17875
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17876
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17877
|
+
***************************************************************************** */
|
|
17878
|
+
|
|
17879
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17880
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17881
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17882
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17883
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17884
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17885
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17886
|
+
});
|
|
17887
|
+
}
|
|
17888
|
+
|
|
17889
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
17890
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
17891
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
17892
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
17893
|
+
}
|
|
17894
|
+
|
|
17895
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
17896
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
17897
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
17898
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
17899
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17900
|
+
}
|
|
17901
|
+
|
|
17902
|
+
var _DroppedAsset_updateDroppedAsset;
|
|
17902
17903
|
class DroppedAsset extends Asset {
|
|
17903
|
-
apiKey
|
|
17904
|
-
|
|
17905
|
-
|
|
17906
|
-
|
|
17907
|
-
|
|
17908
|
-
|
|
17904
|
+
constructor({ apiKey, id, args, urlSlug, }) {
|
|
17905
|
+
super({ apiKey, args });
|
|
17906
|
+
// update dropped assets
|
|
17907
|
+
_DroppedAsset_updateDroppedAsset.set(this, (payload, updateType) => {
|
|
17908
|
+
return new Promise((resolve, reject) => {
|
|
17909
|
+
publicAPI(this.apiKey)
|
|
17910
|
+
.put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload))
|
|
17911
|
+
.then(() => {
|
|
17912
|
+
resolve("Success!");
|
|
17913
|
+
})
|
|
17914
|
+
.catch((error) => {
|
|
17915
|
+
reject(new Error(getErrorMessage(error)));
|
|
17916
|
+
});
|
|
17917
|
+
});
|
|
17918
|
+
});
|
|
17919
|
+
Object.assign(this, args);
|
|
17909
17920
|
this.apiKey = apiKey;
|
|
17910
|
-
this.
|
|
17921
|
+
this.id = id;
|
|
17922
|
+
this.text = args.text;
|
|
17911
17923
|
this.urlSlug = urlSlug;
|
|
17912
|
-
Object.assign(this, args);
|
|
17913
17924
|
this.updateCustomText;
|
|
17914
17925
|
}
|
|
17915
17926
|
// get dropped asset
|
|
@@ -17939,25 +17950,9 @@ class DroppedAsset extends Asset {
|
|
|
17939
17950
|
});
|
|
17940
17951
|
});
|
|
17941
17952
|
}
|
|
17942
|
-
// update dropped assets
|
|
17943
|
-
#updateDroppedAsset = (payload, updateType) => {
|
|
17944
|
-
console.log("apiKey", this.apiKey);
|
|
17945
|
-
return new Promise((resolve, reject) => {
|
|
17946
|
-
publicAPI(this.apiKey)
|
|
17947
|
-
.put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, {
|
|
17948
|
-
...payload,
|
|
17949
|
-
})
|
|
17950
|
-
.then(() => {
|
|
17951
|
-
resolve("Success!");
|
|
17952
|
-
})
|
|
17953
|
-
.catch((error) => {
|
|
17954
|
-
reject(new Error(getErrorMessage(error)));
|
|
17955
|
-
});
|
|
17956
|
-
});
|
|
17957
|
-
};
|
|
17958
17953
|
updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
|
|
17959
17954
|
return new Promise((resolve, reject) => {
|
|
17960
|
-
return this
|
|
17955
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
|
|
17961
17956
|
.then(resolve)
|
|
17962
17957
|
.catch((error) => {
|
|
17963
17958
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -17966,7 +17961,7 @@ class DroppedAsset extends Asset {
|
|
|
17966
17961
|
}
|
|
17967
17962
|
updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
|
|
17968
17963
|
return new Promise((resolve, reject) => {
|
|
17969
|
-
return this
|
|
17964
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
|
|
17970
17965
|
.then(resolve)
|
|
17971
17966
|
.catch((error) => {
|
|
17972
17967
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -17975,7 +17970,7 @@ class DroppedAsset extends Asset {
|
|
|
17975
17970
|
}
|
|
17976
17971
|
updateCustomText(style, text) {
|
|
17977
17972
|
return new Promise((resolve, reject) => {
|
|
17978
|
-
return this
|
|
17973
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { style, text }, "set-custom-text")
|
|
17979
17974
|
.then(resolve)
|
|
17980
17975
|
.catch((error) => {
|
|
17981
17976
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -17984,7 +17979,7 @@ class DroppedAsset extends Asset {
|
|
|
17984
17979
|
}
|
|
17985
17980
|
updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
|
|
17986
17981
|
return new Promise((resolve, reject) => {
|
|
17987
|
-
return this
|
|
17982
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
|
|
17988
17983
|
.then(resolve)
|
|
17989
17984
|
.catch((error) => {
|
|
17990
17985
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -17993,7 +17988,7 @@ class DroppedAsset extends Asset {
|
|
|
17993
17988
|
}
|
|
17994
17989
|
updateMuteZone(isMutezone) {
|
|
17995
17990
|
return new Promise((resolve, reject) => {
|
|
17996
|
-
return this
|
|
17991
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isMutezone }, "set-mute-zone")
|
|
17997
17992
|
.then(resolve)
|
|
17998
17993
|
.catch((error) => {
|
|
17999
17994
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -18002,7 +17997,7 @@ class DroppedAsset extends Asset {
|
|
|
18002
17997
|
}
|
|
18003
17998
|
updatePosition(x, y) {
|
|
18004
17999
|
return new Promise((resolve, reject) => {
|
|
18005
|
-
return this
|
|
18000
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { x, y }, "set-position")
|
|
18006
18001
|
.then(resolve)
|
|
18007
18002
|
.catch((error) => {
|
|
18008
18003
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -18011,7 +18006,7 @@ class DroppedAsset extends Asset {
|
|
|
18011
18006
|
}
|
|
18012
18007
|
updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
|
|
18013
18008
|
return new Promise((resolve, reject) => {
|
|
18014
|
-
return this
|
|
18009
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
|
|
18015
18010
|
.then(resolve)
|
|
18016
18011
|
.catch((error) => {
|
|
18017
18012
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -18020,7 +18015,7 @@ class DroppedAsset extends Asset {
|
|
|
18020
18015
|
}
|
|
18021
18016
|
updateScale(assetScale) {
|
|
18022
18017
|
return new Promise((resolve, reject) => {
|
|
18023
|
-
return this
|
|
18018
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetScale }, "change-scale")
|
|
18024
18019
|
.then(resolve)
|
|
18025
18020
|
.catch((error) => {
|
|
18026
18021
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -18029,7 +18024,7 @@ class DroppedAsset extends Asset {
|
|
|
18029
18024
|
}
|
|
18030
18025
|
updateUploadedMediaSelected(mediaId) {
|
|
18031
18026
|
return new Promise((resolve, reject) => {
|
|
18032
|
-
return this
|
|
18027
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { mediaId }, "change-uploaded-media-selected")
|
|
18033
18028
|
.then(resolve)
|
|
18034
18029
|
.catch((error) => {
|
|
18035
18030
|
reject(new Error(getErrorMessage(error)));
|
|
@@ -18038,82 +18033,23 @@ class DroppedAsset extends Asset {
|
|
|
18038
18033
|
}
|
|
18039
18034
|
updateWebImageLayers(bottom, top) {
|
|
18040
18035
|
return new Promise((resolve, reject) => {
|
|
18041
|
-
return this
|
|
18036
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { bottom, top }, "set-webimage-layers")
|
|
18042
18037
|
.then(resolve)
|
|
18043
18038
|
.catch((error) => {
|
|
18044
18039
|
reject(new Error(getErrorMessage(error)));
|
|
18045
18040
|
});
|
|
18046
18041
|
});
|
|
18047
18042
|
}
|
|
18048
|
-
}
|
|
18049
|
-
|
|
18050
|
-
class Scene {
|
|
18051
|
-
apiKey;
|
|
18052
|
-
email;
|
|
18053
|
-
constructor(apiKey, email) {
|
|
18054
|
-
this.apiKey = apiKey;
|
|
18055
|
-
this.email = email;
|
|
18056
|
-
}
|
|
18057
|
-
fetchScenesByEmail() {
|
|
18058
|
-
return new Promise((resolve, reject) => {
|
|
18059
|
-
publicAPI(this.apiKey)
|
|
18060
|
-
.get(`/scenes/my-scenes?email=${this.email}`)
|
|
18061
|
-
.then((response) => {
|
|
18062
|
-
resolve(response.data);
|
|
18063
|
-
})
|
|
18064
|
-
.catch((error) => {
|
|
18065
|
-
reject(new Error(getErrorMessage(error)));
|
|
18066
|
-
});
|
|
18067
|
-
});
|
|
18068
|
-
}
|
|
18069
|
-
}
|
|
18043
|
+
}
|
|
18044
|
+
_DroppedAsset_updateDroppedAsset = new WeakMap();
|
|
18070
18045
|
|
|
18071
18046
|
class Visitor {
|
|
18072
|
-
apiKey
|
|
18073
|
-
|
|
18074
|
-
displayName;
|
|
18075
|
-
gestureType;
|
|
18076
|
-
hidden;
|
|
18077
|
-
isAdmin;
|
|
18078
|
-
isBackground;
|
|
18079
|
-
isMobile;
|
|
18080
|
-
isRecording;
|
|
18081
|
-
isRecordingBot;
|
|
18082
|
-
lastUpdate;
|
|
18083
|
-
moveFrom;
|
|
18084
|
-
movedOn;
|
|
18085
|
-
moveTo;
|
|
18086
|
-
muted;
|
|
18087
|
-
performer;
|
|
18088
|
-
performerNear;
|
|
18089
|
-
playerId;
|
|
18090
|
-
shareScreen;
|
|
18091
|
-
sitting;
|
|
18092
|
-
urlSlug;
|
|
18093
|
-
username;
|
|
18094
|
-
constructor(apiKey, color = "", displayName, gestureType = 0, hidden = false, isAdmin = false, isBackground = false, isMobile = false, isRecording = false, isRecordingBot = false, lastUpdate = undefined, moveFrom = {}, movedOn = undefined, moveTo = { x: 0, y: 0 }, muted = false, performer = false, performerNear = false, playerId = undefined, shareScreen = false, sitting = false, urlSlug, username = undefined) {
|
|
18047
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
18048
|
+
Object.assign(this, args);
|
|
18095
18049
|
this.apiKey = apiKey;
|
|
18096
|
-
this.
|
|
18097
|
-
this.
|
|
18098
|
-
this.gestureType = gestureType;
|
|
18099
|
-
this.hidden = hidden;
|
|
18100
|
-
this.isAdmin = isAdmin;
|
|
18101
|
-
this.isBackground = isBackground;
|
|
18102
|
-
this.isMobile = isMobile;
|
|
18103
|
-
this.isRecording = isRecording;
|
|
18104
|
-
this.isRecordingBot = isRecordingBot;
|
|
18105
|
-
this.lastUpdate = lastUpdate;
|
|
18106
|
-
this.moveFrom = moveFrom;
|
|
18107
|
-
this.movedOn = movedOn;
|
|
18108
|
-
this.moveTo = moveTo;
|
|
18109
|
-
this.muted = muted;
|
|
18110
|
-
this.performer = performer;
|
|
18111
|
-
this.performerNear = performerNear;
|
|
18112
|
-
this.playerId = playerId;
|
|
18113
|
-
this.shareScreen = shareScreen;
|
|
18114
|
-
this.sitting = sitting;
|
|
18050
|
+
this.moveTo = args.moveTo;
|
|
18051
|
+
this.playerId = args.playerId;
|
|
18115
18052
|
this.urlSlug = urlSlug;
|
|
18116
|
-
this.username = username;
|
|
18117
18053
|
this.moveVisitor;
|
|
18118
18054
|
}
|
|
18119
18055
|
moveVisitor(shouldTeleportVisitor, x, y) {
|
|
@@ -18137,35 +18073,22 @@ class Visitor {
|
|
|
18137
18073
|
}
|
|
18138
18074
|
}
|
|
18139
18075
|
|
|
18076
|
+
var _World_droppedAssetsMap, _World_visitorsMap;
|
|
18140
18077
|
class World {
|
|
18141
|
-
|
|
18142
|
-
|
|
18143
|
-
|
|
18144
|
-
|
|
18145
|
-
|
|
18146
|
-
|
|
18147
|
-
|
|
18148
|
-
|
|
18149
|
-
|
|
18150
|
-
height;
|
|
18151
|
-
heroImage;
|
|
18152
|
-
mapExists;
|
|
18153
|
-
name;
|
|
18154
|
-
redirectTo;
|
|
18155
|
-
spawnPosition;
|
|
18156
|
-
tileBackgroundEverywhere;
|
|
18157
|
-
urlSlug;
|
|
18158
|
-
useTopiaPassword;
|
|
18159
|
-
width;
|
|
18078
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
18079
|
+
_World_droppedAssetsMap.set(this, void 0);
|
|
18080
|
+
_World_visitorsMap.set(this, void 0);
|
|
18081
|
+
Object.assign(this, args);
|
|
18082
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
18083
|
+
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
18084
|
+
this.apiKey = apiKey;
|
|
18085
|
+
this.urlSlug = urlSlug;
|
|
18086
|
+
}
|
|
18160
18087
|
get droppedAssets() {
|
|
18161
|
-
return this
|
|
18088
|
+
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
18162
18089
|
}
|
|
18163
18090
|
get visitors() {
|
|
18164
|
-
return this
|
|
18165
|
-
}
|
|
18166
|
-
constructor(apiKey, urlSlug) {
|
|
18167
|
-
this.apiKey = apiKey;
|
|
18168
|
-
this.urlSlug = urlSlug;
|
|
18091
|
+
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
18169
18092
|
}
|
|
18170
18093
|
// world details
|
|
18171
18094
|
fetchDetails() {
|
|
@@ -18181,11 +18104,22 @@ class World {
|
|
|
18181
18104
|
});
|
|
18182
18105
|
});
|
|
18183
18106
|
}
|
|
18184
|
-
updateDetails() {
|
|
18107
|
+
updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
|
|
18108
|
+
const payload = {
|
|
18109
|
+
controls,
|
|
18110
|
+
description,
|
|
18111
|
+
forceAuthOnLogin,
|
|
18112
|
+
height,
|
|
18113
|
+
name,
|
|
18114
|
+
spawnPosition,
|
|
18115
|
+
width,
|
|
18116
|
+
};
|
|
18185
18117
|
return new Promise((resolve, reject) => {
|
|
18186
18118
|
publicAPI(this.apiKey)
|
|
18187
|
-
.
|
|
18119
|
+
.put(`/world/${this.urlSlug}/world-details`, payload)
|
|
18188
18120
|
.then(() => {
|
|
18121
|
+
const cleanPayload = removeUndefined(payload);
|
|
18122
|
+
Object.assign(this, cleanPayload);
|
|
18189
18123
|
resolve("Success!");
|
|
18190
18124
|
})
|
|
18191
18125
|
.catch((error) => {
|
|
@@ -18202,9 +18136,13 @@ class World {
|
|
|
18202
18136
|
// create temp map and then update private property only once
|
|
18203
18137
|
const tempVisitorsMap = {};
|
|
18204
18138
|
for (const playerId in response.data) {
|
|
18205
|
-
tempVisitorsMap[playerId] =
|
|
18139
|
+
tempVisitorsMap[playerId] = new Visitor({
|
|
18140
|
+
apiKey: this.apiKey,
|
|
18141
|
+
args: response.data[playerId],
|
|
18142
|
+
urlSlug: this.urlSlug,
|
|
18143
|
+
});
|
|
18206
18144
|
}
|
|
18207
|
-
this
|
|
18145
|
+
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
18208
18146
|
resolve("Success!");
|
|
18209
18147
|
})
|
|
18210
18148
|
.catch((error) => {
|
|
@@ -18212,33 +18150,39 @@ class World {
|
|
|
18212
18150
|
});
|
|
18213
18151
|
});
|
|
18214
18152
|
}
|
|
18215
|
-
|
|
18216
|
-
|
|
18217
|
-
|
|
18218
|
-
|
|
18219
|
-
|
|
18220
|
-
|
|
18221
|
-
|
|
18222
|
-
|
|
18153
|
+
currentVisitors() {
|
|
18154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18155
|
+
try {
|
|
18156
|
+
yield this.fetchVisitors();
|
|
18157
|
+
return this.visitors;
|
|
18158
|
+
}
|
|
18159
|
+
catch (error) {
|
|
18160
|
+
return error;
|
|
18161
|
+
}
|
|
18162
|
+
});
|
|
18223
18163
|
}
|
|
18224
|
-
|
|
18225
|
-
|
|
18226
|
-
|
|
18227
|
-
|
|
18228
|
-
|
|
18229
|
-
|
|
18230
|
-
|
|
18231
|
-
|
|
18232
|
-
|
|
18233
|
-
|
|
18164
|
+
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
18165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18166
|
+
if (shouldFetchVisitors)
|
|
18167
|
+
yield this.fetchVisitors();
|
|
18168
|
+
const allPromises = [];
|
|
18169
|
+
if (!this.visitors)
|
|
18170
|
+
return;
|
|
18171
|
+
const objectKeys = Object.keys(this.visitors);
|
|
18172
|
+
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
|
|
18173
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
18174
|
+
return outcomes;
|
|
18175
|
+
});
|
|
18234
18176
|
}
|
|
18235
|
-
|
|
18236
|
-
|
|
18237
|
-
|
|
18238
|
-
|
|
18177
|
+
moveVisitors(visitorsToMove) {
|
|
18178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18179
|
+
const allPromises = [];
|
|
18180
|
+
visitorsToMove.forEach((v) => {
|
|
18181
|
+
allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
|
|
18182
|
+
});
|
|
18183
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
18184
|
+
return outcomes;
|
|
18239
18185
|
});
|
|
18240
|
-
const outcomes = await Promise.allSettled(allPromises);
|
|
18241
|
-
return outcomes;
|
|
18242
18186
|
}
|
|
18243
18187
|
// dropped assets
|
|
18244
18188
|
fetchDroppedAssets() {
|
|
@@ -18250,9 +18194,14 @@ class World {
|
|
|
18250
18194
|
const tempDroppedAssetsMap = {};
|
|
18251
18195
|
for (const id in response.data) {
|
|
18252
18196
|
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
18253
|
-
tempDroppedAssetsMap[id] = new DroppedAsset(
|
|
18197
|
+
tempDroppedAssetsMap[id] = new DroppedAsset({
|
|
18198
|
+
apiKey: this.apiKey,
|
|
18199
|
+
id,
|
|
18200
|
+
args: response.data[id],
|
|
18201
|
+
urlSlug: this.urlSlug,
|
|
18202
|
+
});
|
|
18254
18203
|
}
|
|
18255
|
-
this
|
|
18204
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
18256
18205
|
resolve("Success!");
|
|
18257
18206
|
})
|
|
18258
18207
|
.catch((error) => {
|
|
@@ -18260,15 +18209,81 @@ class World {
|
|
|
18260
18209
|
});
|
|
18261
18210
|
});
|
|
18262
18211
|
}
|
|
18263
|
-
|
|
18264
|
-
|
|
18265
|
-
|
|
18266
|
-
|
|
18267
|
-
|
|
18212
|
+
updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
18213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18214
|
+
// adds ability to update any styles for specified dropped assets only while preserving text
|
|
18215
|
+
const allPromises = [];
|
|
18216
|
+
droppedAssetsToUpdate.forEach((a) => {
|
|
18217
|
+
allPromises.push(a.updateCustomText(style, a.text));
|
|
18218
|
+
});
|
|
18219
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
18220
|
+
return outcomes;
|
|
18268
18221
|
});
|
|
18269
|
-
const outcomes = await Promise.allSettled(allPromises);
|
|
18270
|
-
return outcomes;
|
|
18271
18222
|
}
|
|
18272
|
-
|
|
18223
|
+
// scenes
|
|
18224
|
+
replaceScene(sceneId) {
|
|
18225
|
+
return new Promise((resolve, reject) => {
|
|
18226
|
+
publicAPI(this.apiKey)
|
|
18227
|
+
.put(`/world/${this.urlSlug}/change-scene`, { sceneId })
|
|
18228
|
+
.then(() => {
|
|
18229
|
+
resolve("Success!");
|
|
18230
|
+
})
|
|
18231
|
+
.catch((error) => {
|
|
18232
|
+
reject(new Error(getErrorMessage(error)));
|
|
18233
|
+
});
|
|
18234
|
+
});
|
|
18235
|
+
}
|
|
18236
|
+
}
|
|
18237
|
+
_World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
|
|
18238
|
+
|
|
18239
|
+
var _User_worldsMap;
|
|
18240
|
+
class User {
|
|
18241
|
+
constructor({ apiKey, email }) {
|
|
18242
|
+
_User_worldsMap.set(this, void 0);
|
|
18243
|
+
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
18244
|
+
this.apiKey = apiKey;
|
|
18245
|
+
this.email = email;
|
|
18246
|
+
}
|
|
18247
|
+
get worlds() {
|
|
18248
|
+
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
18249
|
+
}
|
|
18250
|
+
fetchScenesByEmail() {
|
|
18251
|
+
return new Promise((resolve, reject) => {
|
|
18252
|
+
if (!this.email)
|
|
18253
|
+
reject("There is no email associated with this user.");
|
|
18254
|
+
publicAPI(this.apiKey)
|
|
18255
|
+
.get(`/scenes/my-scenes?email=${this.email}`)
|
|
18256
|
+
.then((response) => {
|
|
18257
|
+
resolve(response.data);
|
|
18258
|
+
})
|
|
18259
|
+
.catch((error) => {
|
|
18260
|
+
reject(new Error(getErrorMessage(error)));
|
|
18261
|
+
});
|
|
18262
|
+
});
|
|
18263
|
+
}
|
|
18264
|
+
fetchWorldsByKey() {
|
|
18265
|
+
return new Promise((resolve, reject) => {
|
|
18266
|
+
publicAPI(this.apiKey)
|
|
18267
|
+
.get("/user/worlds")
|
|
18268
|
+
.then((response) => {
|
|
18269
|
+
const tempWorldsMap = {};
|
|
18270
|
+
for (const i in response.data) {
|
|
18271
|
+
const worldDetails = response.data[i];
|
|
18272
|
+
tempWorldsMap[worldDetails.urlSlug] = new World({
|
|
18273
|
+
apiKey: this.apiKey,
|
|
18274
|
+
args: worldDetails,
|
|
18275
|
+
urlSlug: worldDetails.urlSlug,
|
|
18276
|
+
});
|
|
18277
|
+
}
|
|
18278
|
+
__classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
|
|
18279
|
+
resolve("Success!");
|
|
18280
|
+
})
|
|
18281
|
+
.catch((error) => {
|
|
18282
|
+
reject(new Error(getErrorMessage(error)));
|
|
18283
|
+
});
|
|
18284
|
+
});
|
|
18285
|
+
}
|
|
18286
|
+
}
|
|
18287
|
+
_User_worldsMap = new WeakMap();
|
|
18273
18288
|
|
|
18274
|
-
export { Asset, DroppedAsset,
|
|
18289
|
+
export { Asset, DroppedAsset, User, Visitor, World };
|
|
File without changes
|
|
File without changes
|
package/dist/interfaces/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { removeUndefined } from "../removeUndefined";
|
|
2
|
+
afterEach(() => {
|
|
3
|
+
jest.resetAllMocks();
|
|
4
|
+
});
|
|
5
|
+
describe("remove undefined values util", () => {
|
|
6
|
+
it("should return an object without overriding with undefined values", () => {
|
|
7
|
+
const testRemoveUndefined = removeUndefined({ a: "abc", b: undefined, c: "123", d: null });
|
|
8
|
+
expect(testRemoveUndefined).toEqual({ a: "abc", c: "123", d: null });
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -2,10 +2,10 @@ import { scatterVisitors } from "../scatterVisitors";
|
|
|
2
2
|
afterEach(() => {
|
|
3
3
|
jest.resetAllMocks();
|
|
4
4
|
});
|
|
5
|
-
describe("
|
|
6
|
-
it("should
|
|
5
|
+
describe("scatter visitors util", () => {
|
|
6
|
+
it("should scatter visitors by 50", () => {
|
|
7
7
|
const testScatter = scatterVisitors(10, 50);
|
|
8
|
-
expect(testScatter).
|
|
9
|
-
expect(testScatter).
|
|
8
|
+
expect(testScatter).toBeGreaterThanOrEqual(-40);
|
|
9
|
+
expect(testScatter).toBeLessThanOrEqual(60);
|
|
10
10
|
});
|
|
11
11
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const getErrorMessage = (error) => {
|
|
2
|
-
|
|
3
|
-
const errorMessage = error
|
|
2
|
+
var _a, _b, _c;
|
|
3
|
+
const errorMessage = (_c = (_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errors[0]) === null || _c === void 0 ? void 0 : _c.message;
|
|
4
4
|
return errorMessage || "Something went wrong. Please try again or contact support.";
|
|
5
5
|
};
|
package/dist/utils/index.js
CHANGED