@rtsdk/topia 0.0.8 → 0.0.9

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.
Files changed (34) hide show
  1. package/dist/__mocks__/assets.js +241 -0
  2. package/dist/__mocks__/index.js +2 -0
  3. package/dist/__mocks__/scenes.js +104 -0
  4. package/dist/__mocks__/visitors.js +43 -16
  5. package/dist/__mocks__/worlds.js +9 -9
  6. package/dist/controllers/Asset.js +62 -0
  7. package/dist/controllers/DroppedAsset.js +150 -0
  8. package/dist/controllers/Scene.js +22 -0
  9. package/dist/controllers/Visitor.js +70 -0
  10. package/dist/controllers/World.js +125 -110
  11. package/dist/controllers/__tests__/asset.test.js +14 -0
  12. package/dist/controllers/__tests__/droppedAsset.test.js +109 -0
  13. package/dist/controllers/__tests__/scene.test.js +14 -0
  14. package/dist/controllers/__tests__/visitor.test.js +12 -0
  15. package/dist/controllers/__tests__/world.test.js +48 -109
  16. package/dist/controllers/index.js +4 -0
  17. package/dist/index.js +448 -125
  18. package/dist/{types/Visitor.js → interfaces/DroppedAssetInterfaces.js} +0 -0
  19. package/dist/interfaces/WorldInterfaces.js +1 -0
  20. package/dist/interfaces/index.js +2 -0
  21. package/dist/types/DroppedAssetType.js +1 -0
  22. package/dist/types/DroppedAssetTypes.js +12 -0
  23. package/dist/types/VisitorType.js +1 -0
  24. package/dist/types/VisitorTypes.js +1 -0
  25. package/dist/types/Visitors.js +1 -0
  26. package/dist/types/index.js +2 -1
  27. package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
  28. package/dist/utils/createDroppedAsset.js +72 -0
  29. package/dist/utils/createVisitor.js +3 -0
  30. package/dist/utils/getErrorMessage.js +5 -0
  31. package/dist/utils/index.js +4 -0
  32. package/dist/utils/publicAPI.js +11 -0
  33. package/dist/utils/scatterVisitors.js +5 -0
  34. package/package.json +3 -1
package/dist/index.js CHANGED
@@ -11,58 +11,15 @@ import require$$0$2 from 'os';
11
11
  import zlib from 'zlib';
12
12
  import EventEmitter from 'events';
13
13
 
14
- /******************************************************************************
15
- Copyright (c) Microsoft Corporation.
16
-
17
- Permission to use, copy, modify, and/or distribute this software for any
18
- purpose with or without fee is hereby granted.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
- PERFORMANCE OF THIS SOFTWARE.
27
- ***************************************************************************** */
28
-
29
- function __awaiter(thisArg, _arguments, P, generator) {
30
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
- return new (P || (P = Promise))(function (resolve, reject) {
32
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
- step((generator = generator.apply(thisArg, _arguments || [])).next());
36
- });
37
- }
38
-
39
- function __generator(thisArg, body) {
40
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
41
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
42
- function verb(n) { return function (v) { return step([n, v]); }; }
43
- function step(op) {
44
- if (f) throw new TypeError("Generator is already executing.");
45
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
46
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
47
- if (y = 0, t) op = [op[0] & 2, t.value];
48
- switch (op[0]) {
49
- case 0: case 1: t = op; break;
50
- case 4: _.label++; return { value: op[1], done: false };
51
- case 5: _.label++; y = op[1]; op = [0]; continue;
52
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
53
- default:
54
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
55
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
56
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
57
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
58
- if (t[2]) _.ops.pop();
59
- _.trys.pop(); continue;
60
- }
61
- op = body.call(thisArg, _);
62
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
63
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
64
- }
65
- }
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
+ const getErrorMessage = (error) => {
19
+ console.log("🚀 ~ file: getErrorMessage.ts:2 ~ getErrorMessage ~ error", error);
20
+ const errorMessage = error?.response?.data?.errors[0]?.message;
21
+ return errorMessage || "Something went wrong. Please try again or contact support.";
22
+ };
66
23
 
67
24
  function bind(fn, thisArg) {
68
25
  return function wrap() {
@@ -17864,88 +17821,454 @@ axios.formToJSON = thing => {
17864
17821
  return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
17865
17822
  };
17866
17823
 
17867
- var API_URL = "https://api.topia.io/api";
17868
- var World = /** @class */ (function () {
17869
- function World(apiKey, urlSlug) {
17824
+ const publicAPI = (apiKey) => {
17825
+ return axios.create({
17826
+ baseURL: "https://api.topia.io/api",
17827
+ headers: {
17828
+ "Accept-Encoding": "",
17829
+ "Authorization": apiKey,
17830
+ "Content-Type": "application/json",
17831
+ },
17832
+ });
17833
+ };
17834
+
17835
+ const scatterVisitors = (original, scatterBy) => {
17836
+ const min = original - scatterBy;
17837
+ const max = original + scatterBy;
17838
+ return Math.floor(Math.random() * (max - min) + min);
17839
+ };
17840
+
17841
+ class Asset {
17842
+ addedOn;
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;
17870
17866
  this.apiKey = apiKey;
17867
+ this.assetName = assetName;
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;
17871
17886
  this.urlSlug = urlSlug;
17872
17887
  }
17873
- World.prototype.fetchDetails = function () {
17874
- return __awaiter(this, void 0, void 0, function () {
17875
- var _this = this;
17876
- return __generator(this, function (_a) {
17877
- return [2 /*return*/, new Promise(function (resolve, reject) {
17878
- axios
17879
- .get("".concat(API_URL, "/world/").concat(_this.urlSlug, "/world-details"), {
17880
- headers: { Authorization: _this.apiKey }
17881
- })
17882
- .then(function (response) {
17883
- resolve(response.data);
17884
- })["catch"](reject);
17885
- })];
17888
+ fetchAssetsByEmail(ownerEmail) {
17889
+ return new Promise((resolve, reject) => {
17890
+ publicAPI(this.apiKey)
17891
+ .get(`/assets/my-assets?email=${ownerEmail}`)
17892
+ .then((response) => {
17893
+ resolve(response.data);
17894
+ })
17895
+ .catch((error) => {
17896
+ reject(new Error(getErrorMessage(error)));
17886
17897
  });
17887
17898
  });
17888
- };
17889
- World.prototype.fetchVisitors = function () {
17890
- return __awaiter(this, void 0, void 0, function () {
17891
- var _this = this;
17892
- return __generator(this, function (_a) {
17893
- return [2 /*return*/, new Promise(function (resolve, reject) {
17894
- axios
17895
- .get("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors"), {
17896
- headers: { Authorization: _this.apiKey }
17897
- })
17898
- .then(function (response) {
17899
- resolve(response.data);
17900
- })["catch"](reject);
17901
- })];
17899
+ }
17900
+ }
17901
+
17902
+ class DroppedAsset extends Asset {
17903
+ apiKey;
17904
+ text;
17905
+ urlSlug;
17906
+ // TODO: should we explicitly declare each or simplify with Object.assign for all optional properties? (kinda breaks the ts rules but looks so much nicer!)
17907
+ constructor(apiKey, args, text, urlSlug) {
17908
+ super(args.addedOn, apiKey, args.assetName, args.creatorTags, args.id, args.isPublic, args.kitId, args.layer0, args.layer1, args.library, args.originalAssetId, args.originalKit, args.ownerId, args.ownerName, args.platformAsset, args.purchased, args.purchaseDate, args.purchasedFrom, args.specialType, args.transactionId, args.type, urlSlug);
17909
+ this.apiKey = apiKey;
17910
+ this.text = text;
17911
+ this.urlSlug = urlSlug;
17912
+ Object.assign(this, args);
17913
+ this.updateCustomText;
17914
+ }
17915
+ // get dropped asset
17916
+ fetchDroppedAssetById() {
17917
+ return new Promise((resolve, reject) => {
17918
+ publicAPI(this.apiKey)
17919
+ .get(`/world/${this.urlSlug}/assets/${this.id}`)
17920
+ .then((response) => {
17921
+ Object.assign(this, response.data);
17922
+ resolve("Success!");
17923
+ })
17924
+ .catch((error) => {
17925
+ reject(new Error(getErrorMessage(error)));
17926
+ });
17927
+ });
17928
+ }
17929
+ // delete dropped asset
17930
+ deleteDroppedAsset() {
17931
+ return new Promise((resolve, reject) => {
17932
+ publicAPI(this.apiKey)
17933
+ .delete(`/world/${this.urlSlug}/assets/${this.id}`)
17934
+ .then(() => {
17935
+ resolve("Success!");
17936
+ })
17937
+ .catch((error) => {
17938
+ reject(new Error(getErrorMessage(error)));
17939
+ });
17940
+ });
17941
+ }
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)));
17902
17955
  });
17903
17956
  });
17904
17957
  };
17905
- World.prototype.moveVisitors = function (visitors) {
17906
- return __awaiter(this, void 0, void 0, function () {
17907
- var allPromises, outcomes;
17908
- var _this = this;
17909
- return __generator(this, function (_a) {
17910
- switch (_a.label) {
17911
- case 0:
17912
- allPromises = [];
17913
- visitors.map(function (visitor) { return __awaiter(_this, void 0, void 0, function () {
17914
- var promise;
17915
- var _this = this;
17916
- return __generator(this, function (_a) {
17917
- promise = new Promise(function (resolve, reject) {
17918
- var requestOptions = {
17919
- headers: { Authorization: _this.apiKey },
17920
- body: {
17921
- moveTo: {
17922
- x: visitor.coordinates.x,
17923
- y: visitor.coordinates.y
17924
- },
17925
- teleport: true
17926
- }
17927
- };
17928
- axios
17929
- .put("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors/").concat(visitor.id, "/move"), requestOptions)
17930
- .then(function (response) {
17931
- resolve(response.data);
17932
- })["catch"](reject);
17933
- });
17934
- allPromises.push(promise);
17935
- return [2 /*return*/];
17936
- });
17937
- }); });
17938
- return [4 /*yield*/, Promise.allSettled(allPromises)];
17939
- case 1:
17940
- outcomes = _a.sent();
17941
- // const succeeded = outcomes.filter((o) => o.status === "fulfilled");
17942
- // const failed = outcomes.filter((o) => o.status === "rejected");
17943
- return [2 /*return*/, outcomes];
17958
+ updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
17959
+ return new Promise((resolve, reject) => {
17960
+ return this.#updateDroppedAsset({ assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
17961
+ .then(resolve)
17962
+ .catch((error) => {
17963
+ reject(new Error(getErrorMessage(error)));
17964
+ });
17965
+ });
17966
+ }
17967
+ updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
17968
+ return new Promise((resolve, reject) => {
17969
+ return this.#updateDroppedAsset({ clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
17970
+ .then(resolve)
17971
+ .catch((error) => {
17972
+ reject(new Error(getErrorMessage(error)));
17973
+ });
17974
+ });
17975
+ }
17976
+ updateCustomText(style, text) {
17977
+ return new Promise((resolve, reject) => {
17978
+ return this.#updateDroppedAsset({ style, text }, "set-custom-text")
17979
+ .then(resolve)
17980
+ .catch((error) => {
17981
+ reject(new Error(getErrorMessage(error)));
17982
+ });
17983
+ });
17984
+ }
17985
+ updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
17986
+ return new Promise((resolve, reject) => {
17987
+ return this.#updateDroppedAsset({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
17988
+ .then(resolve)
17989
+ .catch((error) => {
17990
+ reject(new Error(getErrorMessage(error)));
17991
+ });
17992
+ });
17993
+ }
17994
+ updateMuteZone(isMutezone) {
17995
+ return new Promise((resolve, reject) => {
17996
+ return this.#updateDroppedAsset({ isMutezone }, "set-mute-zone")
17997
+ .then(resolve)
17998
+ .catch((error) => {
17999
+ reject(new Error(getErrorMessage(error)));
18000
+ });
18001
+ });
18002
+ }
18003
+ updatePosition(x, y) {
18004
+ return new Promise((resolve, reject) => {
18005
+ return this.#updateDroppedAsset({ x, y }, "set-position")
18006
+ .then(resolve)
18007
+ .catch((error) => {
18008
+ reject(new Error(getErrorMessage(error)));
18009
+ });
18010
+ });
18011
+ }
18012
+ updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
18013
+ return new Promise((resolve, reject) => {
18014
+ return this.#updateDroppedAsset({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
18015
+ .then(resolve)
18016
+ .catch((error) => {
18017
+ reject(new Error(getErrorMessage(error)));
18018
+ });
18019
+ });
18020
+ }
18021
+ updateScale(assetScale) {
18022
+ return new Promise((resolve, reject) => {
18023
+ return this.#updateDroppedAsset({ assetScale }, "change-scale")
18024
+ .then(resolve)
18025
+ .catch((error) => {
18026
+ reject(new Error(getErrorMessage(error)));
18027
+ });
18028
+ });
18029
+ }
18030
+ updateUploadedMediaSelected(mediaId) {
18031
+ return new Promise((resolve, reject) => {
18032
+ return this.#updateDroppedAsset({ mediaId }, "change-uploaded-media-selected")
18033
+ .then(resolve)
18034
+ .catch((error) => {
18035
+ reject(new Error(getErrorMessage(error)));
18036
+ });
18037
+ });
18038
+ }
18039
+ updateWebImageLayers(bottom, top) {
18040
+ return new Promise((resolve, reject) => {
18041
+ return this.#updateDroppedAsset({ bottom, top }, "set-webimage-layers")
18042
+ .then(resolve)
18043
+ .catch((error) => {
18044
+ reject(new Error(getErrorMessage(error)));
18045
+ });
18046
+ });
18047
+ }
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
+ }
18070
+
18071
+ class Visitor {
18072
+ apiKey;
18073
+ color;
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) {
18095
+ this.apiKey = apiKey;
18096
+ this.color = color;
18097
+ this.displayName = displayName;
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;
18115
+ this.urlSlug = urlSlug;
18116
+ this.username = username;
18117
+ this.moveVisitor;
18118
+ }
18119
+ moveVisitor(shouldTeleportVisitor, x, y) {
18120
+ return new Promise((resolve, reject) => {
18121
+ publicAPI(this.apiKey)
18122
+ .put(`/world/${this.urlSlug}/visitors/${this.playerId}/move`, {
18123
+ moveTo: {
18124
+ x,
18125
+ y,
18126
+ },
18127
+ teleport: shouldTeleportVisitor,
18128
+ })
18129
+ .then(() => {
18130
+ this.moveTo = { x, y };
18131
+ resolve("Success!");
18132
+ })
18133
+ .catch((error) => {
18134
+ reject(new Error(getErrorMessage(error)));
18135
+ });
18136
+ });
18137
+ }
18138
+ }
18139
+
18140
+ class World {
18141
+ #droppedAssetsMap;
18142
+ #visitorsMap;
18143
+ apiKey;
18144
+ background;
18145
+ controls;
18146
+ created;
18147
+ description;
18148
+ enforceWhitelistOnLogin;
18149
+ forceAuthOnLogin;
18150
+ height;
18151
+ heroImage;
18152
+ mapExists;
18153
+ name;
18154
+ redirectTo;
18155
+ spawnPosition;
18156
+ tileBackgroundEverywhere;
18157
+ urlSlug;
18158
+ useTopiaPassword;
18159
+ width;
18160
+ get droppedAssets() {
18161
+ return this.#droppedAssetsMap;
18162
+ }
18163
+ get visitors() {
18164
+ return this.#visitorsMap;
18165
+ }
18166
+ constructor(apiKey, urlSlug) {
18167
+ this.apiKey = apiKey;
18168
+ this.urlSlug = urlSlug;
18169
+ }
18170
+ // world details
18171
+ fetchDetails() {
18172
+ return new Promise((resolve, reject) => {
18173
+ publicAPI(this.apiKey)
18174
+ .get(`/world/${this.urlSlug}/world-details`)
18175
+ .then((response) => {
18176
+ Object.assign(this, response.data);
18177
+ resolve("Success!");
18178
+ })
18179
+ .catch((error) => {
18180
+ reject(new Error(getErrorMessage(error)));
18181
+ });
18182
+ });
18183
+ }
18184
+ updateDetails() {
18185
+ return new Promise((resolve, reject) => {
18186
+ publicAPI(this.apiKey)
18187
+ .get(`/world/${this.urlSlug}/world-details`)
18188
+ .then(() => {
18189
+ resolve("Success!");
18190
+ })
18191
+ .catch((error) => {
18192
+ reject(new Error(getErrorMessage(error)));
18193
+ });
18194
+ });
18195
+ }
18196
+ // visitors
18197
+ fetchVisitors() {
18198
+ return new Promise((resolve, reject) => {
18199
+ publicAPI(this.apiKey)
18200
+ .get(`/world/${this.urlSlug}/visitors`)
18201
+ .then((response) => {
18202
+ // create temp map and then update private property only once
18203
+ const tempVisitorsMap = {};
18204
+ for (const playerId in response.data) {
18205
+ tempVisitorsMap[playerId] = createVisitor(Visitor, this.apiKey, response.data[playerId], this.urlSlug);
17944
18206
  }
18207
+ this.#visitorsMap = tempVisitorsMap;
18208
+ resolve("Success!");
18209
+ })
18210
+ .catch((error) => {
18211
+ reject(new Error(getErrorMessage(error)));
17945
18212
  });
17946
18213
  });
17947
- };
17948
- return World;
17949
- }());
18214
+ }
18215
+ async currentVisitors() {
18216
+ try {
18217
+ await this.fetchVisitors();
18218
+ return this.visitors;
18219
+ }
18220
+ catch (error) {
18221
+ return error;
18222
+ }
18223
+ }
18224
+ async moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
18225
+ if (shouldFetchVisitors)
18226
+ await this.fetchVisitors();
18227
+ const allPromises = [];
18228
+ if (!this.visitors)
18229
+ return;
18230
+ const objectKeys = Object.keys(this.visitors);
18231
+ objectKeys.forEach((key) => allPromises.push(this.#visitorsMap[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
18232
+ const outcomes = await Promise.allSettled(allPromises);
18233
+ return outcomes;
18234
+ }
18235
+ async moveVisitors(visitorsToMove) {
18236
+ const allPromises = [];
18237
+ visitorsToMove.forEach((v) => {
18238
+ allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
18239
+ });
18240
+ const outcomes = await Promise.allSettled(allPromises);
18241
+ return outcomes;
18242
+ }
18243
+ // dropped assets
18244
+ fetchDroppedAssets() {
18245
+ return new Promise((resolve, reject) => {
18246
+ publicAPI(this.apiKey)
18247
+ .get(`/world/${this.urlSlug}/assets`)
18248
+ .then((response) => {
18249
+ // create temp map and then update private property only once
18250
+ const tempDroppedAssetsMap = {};
18251
+ for (const id in response.data) {
18252
+ // tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
18253
+ tempDroppedAssetsMap[id] = new DroppedAsset(this.apiKey, response.data[id], "", this.urlSlug);
18254
+ }
18255
+ this.#droppedAssetsMap = tempDroppedAssetsMap;
18256
+ resolve("Success!");
18257
+ })
18258
+ .catch((error) => {
18259
+ reject(new Error(getErrorMessage(error)));
18260
+ });
18261
+ });
18262
+ }
18263
+ async updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
18264
+ // adds ability to update any styles for specified dropped assets only while preserving text
18265
+ const allPromises = [];
18266
+ droppedAssetsToUpdate.forEach((a) => {
18267
+ allPromises.push(a.updateCustomText(style, a.text));
18268
+ });
18269
+ const outcomes = await Promise.allSettled(allPromises);
18270
+ return outcomes;
18271
+ }
18272
+ }
17950
18273
 
17951
- export { World };
18274
+ export { Asset, DroppedAsset, Scene, Visitor, World };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./DroppedAssetInterfaces";
2
+ export * from "./WorldInterfaces";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export var DroppedAssetClickType;
2
+ (function (DroppedAssetClickType) {
3
+ DroppedAssetClickType["NONE"] = "none";
4
+ DroppedAssetClickType["LINK"] = "link";
5
+ DroppedAssetClickType["PORTAL"] = "portal";
6
+ DroppedAssetClickType["TELEPORT"] = "teleport";
7
+ })(DroppedAssetClickType || (DroppedAssetClickType = {}));
8
+ export var DroppedAssetMediaType;
9
+ (function (DroppedAssetMediaType) {
10
+ DroppedAssetMediaType["NONE"] = "none";
11
+ DroppedAssetMediaType["LINK"] = "link";
12
+ })(DroppedAssetMediaType || (DroppedAssetMediaType = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1,2 @@
1
- export {};
1
+ export * from "./DroppedAssetTypes";
2
+ export * from "./VisitorTypes";
@@ -0,0 +1,11 @@
1
+ import { scatterVisitors } from "../scatterVisitors";
2
+ afterEach(() => {
3
+ jest.resetAllMocks();
4
+ });
5
+ describe("Visitor Class", () => {
6
+ it("should create an instance of Visitor", () => {
7
+ const testScatter = scatterVisitors(10, 50);
8
+ expect(testScatter).toBeGreaterThan(-40);
9
+ expect(testScatter).toBeLessThan(60);
10
+ });
11
+ });