@rtsdk/topia 0.0.8 → 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__/assets.js +241 -0
- package/dist/__mocks__/index.js +2 -0
- package/dist/__mocks__/scenes.js +104 -0
- package/dist/__mocks__/visitors.js +43 -16
- package/dist/__mocks__/worlds.js +10 -9
- package/dist/controllers/Asset.js +20 -0
- package/dist/controllers/DroppedAsset.js +151 -0
- package/dist/controllers/User.js +63 -0
- package/dist/controllers/Visitor.js +31 -0
- package/dist/controllers/World.js +165 -101
- package/dist/controllers/__tests__/asset.test.js +23 -0
- package/dist/controllers/__tests__/droppedAsset.test.js +93 -0
- package/dist/controllers/__tests__/user.test.js +23 -0
- package/dist/controllers/__tests__/visitor.test.js +24 -0
- package/dist/controllers/__tests__/world.test.js +62 -98
- package/dist/controllers/index.js +4 -0
- package/dist/index.js +464 -126
- package/dist/{types/Visitor.js → interfaces/AssetInterfaces.js} +0 -0
- package/dist/interfaces/DroppedAssetInterfaces.js +1 -0
- package/dist/interfaces/VisitorInterfaces.js +1 -0
- package/dist/interfaces/WorldInterfaces.js +1 -0
- package/dist/interfaces/index.js +4 -0
- package/dist/types/DroppedAssetTypes.js +12 -0
- package/dist/types/VisitorTypes.js +1 -0
- package/dist/types/index.js +2 -1
- package/dist/utils/__tests__/removeUndefined.test.js +10 -0
- package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
- package/dist/utils/createDroppedAsset.js +72 -0
- package/dist/utils/getErrorMessage.js +5 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/publicAPI.js +10 -0
- package/dist/utils/removeUndefined.js +8 -0
- package/dist/utils/scatterVisitors.js +5 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -11,58 +11,11 @@ import require$$0$2 from 'os';
|
|
|
11
11
|
import zlib from 'zlib';
|
|
12
12
|
import EventEmitter from 'events';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 getErrorMessage = (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;
|
|
17
|
+
return errorMessage || "Something went wrong. Please try again or contact support.";
|
|
18
|
+
};
|
|
66
19
|
|
|
67
20
|
function bind(fn, thisArg) {
|
|
68
21
|
return function wrap() {
|
|
@@ -17864,88 +17817,473 @@ axios.formToJSON = thing => {
|
|
|
17864
17817
|
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
17865
17818
|
};
|
|
17866
17819
|
|
|
17867
|
-
|
|
17868
|
-
|
|
17869
|
-
|
|
17820
|
+
const publicAPI = (apiKey) => {
|
|
17821
|
+
return axios.create({
|
|
17822
|
+
baseURL: "https://api.topia.io/api",
|
|
17823
|
+
headers: {
|
|
17824
|
+
"Authorization": apiKey,
|
|
17825
|
+
"Content-Type": "application/json",
|
|
17826
|
+
},
|
|
17827
|
+
});
|
|
17828
|
+
};
|
|
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
|
+
|
|
17839
|
+
const scatterVisitors = (original, scatterBy) => {
|
|
17840
|
+
const min = original - scatterBy;
|
|
17841
|
+
const max = original + scatterBy;
|
|
17842
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
17843
|
+
};
|
|
17844
|
+
|
|
17845
|
+
class Asset {
|
|
17846
|
+
constructor({ apiKey, args }) {
|
|
17870
17847
|
this.apiKey = apiKey;
|
|
17848
|
+
Object.assign(this, args);
|
|
17849
|
+
}
|
|
17850
|
+
fetchAssetsByEmail(ownerEmail) {
|
|
17851
|
+
return new Promise((resolve, reject) => {
|
|
17852
|
+
publicAPI(this.apiKey)
|
|
17853
|
+
.get(`/assets/my-assets?email=${ownerEmail}`)
|
|
17854
|
+
.then((response) => {
|
|
17855
|
+
resolve(response.data);
|
|
17856
|
+
})
|
|
17857
|
+
.catch((error) => {
|
|
17858
|
+
reject(new Error(getErrorMessage(error)));
|
|
17859
|
+
});
|
|
17860
|
+
});
|
|
17861
|
+
}
|
|
17862
|
+
}
|
|
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;
|
|
17903
|
+
class DroppedAsset extends Asset {
|
|
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);
|
|
17920
|
+
this.apiKey = apiKey;
|
|
17921
|
+
this.id = id;
|
|
17922
|
+
this.text = args.text;
|
|
17871
17923
|
this.urlSlug = urlSlug;
|
|
17924
|
+
this.updateCustomText;
|
|
17925
|
+
}
|
|
17926
|
+
// get dropped asset
|
|
17927
|
+
fetchDroppedAssetById() {
|
|
17928
|
+
return new Promise((resolve, reject) => {
|
|
17929
|
+
publicAPI(this.apiKey)
|
|
17930
|
+
.get(`/world/${this.urlSlug}/assets/${this.id}`)
|
|
17931
|
+
.then((response) => {
|
|
17932
|
+
Object.assign(this, response.data);
|
|
17933
|
+
resolve("Success!");
|
|
17934
|
+
})
|
|
17935
|
+
.catch((error) => {
|
|
17936
|
+
reject(new Error(getErrorMessage(error)));
|
|
17937
|
+
});
|
|
17938
|
+
});
|
|
17872
17939
|
}
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
|
|
17876
|
-
|
|
17877
|
-
|
|
17878
|
-
|
|
17879
|
-
|
|
17880
|
-
|
|
17881
|
-
|
|
17882
|
-
|
|
17883
|
-
resolve(response.data);
|
|
17884
|
-
})["catch"](reject);
|
|
17885
|
-
})];
|
|
17940
|
+
// delete dropped asset
|
|
17941
|
+
deleteDroppedAsset() {
|
|
17942
|
+
return new Promise((resolve, reject) => {
|
|
17943
|
+
publicAPI(this.apiKey)
|
|
17944
|
+
.delete(`/world/${this.urlSlug}/assets/${this.id}`)
|
|
17945
|
+
.then(() => {
|
|
17946
|
+
resolve("Success!");
|
|
17947
|
+
})
|
|
17948
|
+
.catch((error) => {
|
|
17949
|
+
reject(new Error(getErrorMessage(error)));
|
|
17886
17950
|
});
|
|
17887
17951
|
});
|
|
17888
|
-
}
|
|
17889
|
-
|
|
17890
|
-
return
|
|
17891
|
-
|
|
17892
|
-
|
|
17893
|
-
|
|
17894
|
-
|
|
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
|
-
})];
|
|
17952
|
+
}
|
|
17953
|
+
updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
|
|
17954
|
+
return new Promise((resolve, reject) => {
|
|
17955
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
|
|
17956
|
+
.then(resolve)
|
|
17957
|
+
.catch((error) => {
|
|
17958
|
+
reject(new Error(getErrorMessage(error)));
|
|
17902
17959
|
});
|
|
17903
17960
|
});
|
|
17904
|
-
}
|
|
17905
|
-
|
|
17906
|
-
return
|
|
17907
|
-
|
|
17908
|
-
|
|
17909
|
-
|
|
17910
|
-
|
|
17911
|
-
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
|
|
17929
|
-
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
17941
|
-
|
|
17942
|
-
|
|
17943
|
-
|
|
17961
|
+
}
|
|
17962
|
+
updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
|
|
17963
|
+
return new Promise((resolve, reject) => {
|
|
17964
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
|
|
17965
|
+
.then(resolve)
|
|
17966
|
+
.catch((error) => {
|
|
17967
|
+
reject(new Error(getErrorMessage(error)));
|
|
17968
|
+
});
|
|
17969
|
+
});
|
|
17970
|
+
}
|
|
17971
|
+
updateCustomText(style, text) {
|
|
17972
|
+
return new Promise((resolve, reject) => {
|
|
17973
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { style, text }, "set-custom-text")
|
|
17974
|
+
.then(resolve)
|
|
17975
|
+
.catch((error) => {
|
|
17976
|
+
reject(new Error(getErrorMessage(error)));
|
|
17977
|
+
});
|
|
17978
|
+
});
|
|
17979
|
+
}
|
|
17980
|
+
updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
|
|
17981
|
+
return new Promise((resolve, reject) => {
|
|
17982
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
|
|
17983
|
+
.then(resolve)
|
|
17984
|
+
.catch((error) => {
|
|
17985
|
+
reject(new Error(getErrorMessage(error)));
|
|
17986
|
+
});
|
|
17987
|
+
});
|
|
17988
|
+
}
|
|
17989
|
+
updateMuteZone(isMutezone) {
|
|
17990
|
+
return new Promise((resolve, reject) => {
|
|
17991
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isMutezone }, "set-mute-zone")
|
|
17992
|
+
.then(resolve)
|
|
17993
|
+
.catch((error) => {
|
|
17994
|
+
reject(new Error(getErrorMessage(error)));
|
|
17995
|
+
});
|
|
17996
|
+
});
|
|
17997
|
+
}
|
|
17998
|
+
updatePosition(x, y) {
|
|
17999
|
+
return new Promise((resolve, reject) => {
|
|
18000
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { x, y }, "set-position")
|
|
18001
|
+
.then(resolve)
|
|
18002
|
+
.catch((error) => {
|
|
18003
|
+
reject(new Error(getErrorMessage(error)));
|
|
18004
|
+
});
|
|
18005
|
+
});
|
|
18006
|
+
}
|
|
18007
|
+
updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
|
|
18008
|
+
return new Promise((resolve, reject) => {
|
|
18009
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
|
|
18010
|
+
.then(resolve)
|
|
18011
|
+
.catch((error) => {
|
|
18012
|
+
reject(new Error(getErrorMessage(error)));
|
|
18013
|
+
});
|
|
18014
|
+
});
|
|
18015
|
+
}
|
|
18016
|
+
updateScale(assetScale) {
|
|
18017
|
+
return new Promise((resolve, reject) => {
|
|
18018
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetScale }, "change-scale")
|
|
18019
|
+
.then(resolve)
|
|
18020
|
+
.catch((error) => {
|
|
18021
|
+
reject(new Error(getErrorMessage(error)));
|
|
18022
|
+
});
|
|
18023
|
+
});
|
|
18024
|
+
}
|
|
18025
|
+
updateUploadedMediaSelected(mediaId) {
|
|
18026
|
+
return new Promise((resolve, reject) => {
|
|
18027
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { mediaId }, "change-uploaded-media-selected")
|
|
18028
|
+
.then(resolve)
|
|
18029
|
+
.catch((error) => {
|
|
18030
|
+
reject(new Error(getErrorMessage(error)));
|
|
18031
|
+
});
|
|
18032
|
+
});
|
|
18033
|
+
}
|
|
18034
|
+
updateWebImageLayers(bottom, top) {
|
|
18035
|
+
return new Promise((resolve, reject) => {
|
|
18036
|
+
return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { bottom, top }, "set-webimage-layers")
|
|
18037
|
+
.then(resolve)
|
|
18038
|
+
.catch((error) => {
|
|
18039
|
+
reject(new Error(getErrorMessage(error)));
|
|
18040
|
+
});
|
|
18041
|
+
});
|
|
18042
|
+
}
|
|
18043
|
+
}
|
|
18044
|
+
_DroppedAsset_updateDroppedAsset = new WeakMap();
|
|
18045
|
+
|
|
18046
|
+
class Visitor {
|
|
18047
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
18048
|
+
Object.assign(this, args);
|
|
18049
|
+
this.apiKey = apiKey;
|
|
18050
|
+
this.moveTo = args.moveTo;
|
|
18051
|
+
this.playerId = args.playerId;
|
|
18052
|
+
this.urlSlug = urlSlug;
|
|
18053
|
+
this.moveVisitor;
|
|
18054
|
+
}
|
|
18055
|
+
moveVisitor(shouldTeleportVisitor, x, y) {
|
|
18056
|
+
return new Promise((resolve, reject) => {
|
|
18057
|
+
publicAPI(this.apiKey)
|
|
18058
|
+
.put(`/world/${this.urlSlug}/visitors/${this.playerId}/move`, {
|
|
18059
|
+
moveTo: {
|
|
18060
|
+
x,
|
|
18061
|
+
y,
|
|
18062
|
+
},
|
|
18063
|
+
teleport: shouldTeleportVisitor,
|
|
18064
|
+
})
|
|
18065
|
+
.then(() => {
|
|
18066
|
+
this.moveTo = { x, y };
|
|
18067
|
+
resolve("Success!");
|
|
18068
|
+
})
|
|
18069
|
+
.catch((error) => {
|
|
18070
|
+
reject(new Error(getErrorMessage(error)));
|
|
18071
|
+
});
|
|
18072
|
+
});
|
|
18073
|
+
}
|
|
18074
|
+
}
|
|
18075
|
+
|
|
18076
|
+
var _World_droppedAssetsMap, _World_visitorsMap;
|
|
18077
|
+
class World {
|
|
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
|
+
}
|
|
18087
|
+
get droppedAssets() {
|
|
18088
|
+
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
18089
|
+
}
|
|
18090
|
+
get visitors() {
|
|
18091
|
+
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
18092
|
+
}
|
|
18093
|
+
// world details
|
|
18094
|
+
fetchDetails() {
|
|
18095
|
+
return new Promise((resolve, reject) => {
|
|
18096
|
+
publicAPI(this.apiKey)
|
|
18097
|
+
.get(`/world/${this.urlSlug}/world-details`)
|
|
18098
|
+
.then((response) => {
|
|
18099
|
+
Object.assign(this, response.data);
|
|
18100
|
+
resolve("Success!");
|
|
18101
|
+
})
|
|
18102
|
+
.catch((error) => {
|
|
18103
|
+
reject(new Error(getErrorMessage(error)));
|
|
18104
|
+
});
|
|
18105
|
+
});
|
|
18106
|
+
}
|
|
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
|
+
};
|
|
18117
|
+
return new Promise((resolve, reject) => {
|
|
18118
|
+
publicAPI(this.apiKey)
|
|
18119
|
+
.put(`/world/${this.urlSlug}/world-details`, payload)
|
|
18120
|
+
.then(() => {
|
|
18121
|
+
const cleanPayload = removeUndefined(payload);
|
|
18122
|
+
Object.assign(this, cleanPayload);
|
|
18123
|
+
resolve("Success!");
|
|
18124
|
+
})
|
|
18125
|
+
.catch((error) => {
|
|
18126
|
+
reject(new Error(getErrorMessage(error)));
|
|
18127
|
+
});
|
|
18128
|
+
});
|
|
18129
|
+
}
|
|
18130
|
+
// visitors
|
|
18131
|
+
fetchVisitors() {
|
|
18132
|
+
return new Promise((resolve, reject) => {
|
|
18133
|
+
publicAPI(this.apiKey)
|
|
18134
|
+
.get(`/world/${this.urlSlug}/visitors`)
|
|
18135
|
+
.then((response) => {
|
|
18136
|
+
// create temp map and then update private property only once
|
|
18137
|
+
const tempVisitorsMap = {};
|
|
18138
|
+
for (const playerId in response.data) {
|
|
18139
|
+
tempVisitorsMap[playerId] = new Visitor({
|
|
18140
|
+
apiKey: this.apiKey,
|
|
18141
|
+
args: response.data[playerId],
|
|
18142
|
+
urlSlug: this.urlSlug,
|
|
18143
|
+
});
|
|
18144
|
+
}
|
|
18145
|
+
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
18146
|
+
resolve("Success!");
|
|
18147
|
+
})
|
|
18148
|
+
.catch((error) => {
|
|
18149
|
+
reject(new Error(getErrorMessage(error)));
|
|
18150
|
+
});
|
|
18151
|
+
});
|
|
18152
|
+
}
|
|
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
|
+
});
|
|
18163
|
+
}
|
|
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
|
+
});
|
|
18176
|
+
}
|
|
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;
|
|
18185
|
+
});
|
|
18186
|
+
}
|
|
18187
|
+
// dropped assets
|
|
18188
|
+
fetchDroppedAssets() {
|
|
18189
|
+
return new Promise((resolve, reject) => {
|
|
18190
|
+
publicAPI(this.apiKey)
|
|
18191
|
+
.get(`/world/${this.urlSlug}/assets`)
|
|
18192
|
+
.then((response) => {
|
|
18193
|
+
// create temp map and then update private property only once
|
|
18194
|
+
const tempDroppedAssetsMap = {};
|
|
18195
|
+
for (const id in response.data) {
|
|
18196
|
+
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
18197
|
+
tempDroppedAssetsMap[id] = new DroppedAsset({
|
|
18198
|
+
apiKey: this.apiKey,
|
|
18199
|
+
id,
|
|
18200
|
+
args: response.data[id],
|
|
18201
|
+
urlSlug: this.urlSlug,
|
|
18202
|
+
});
|
|
17944
18203
|
}
|
|
18204
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
18205
|
+
resolve("Success!");
|
|
18206
|
+
})
|
|
18207
|
+
.catch((error) => {
|
|
18208
|
+
reject(new Error(getErrorMessage(error)));
|
|
17945
18209
|
});
|
|
17946
18210
|
});
|
|
17947
|
-
}
|
|
17948
|
-
|
|
17949
|
-
|
|
18211
|
+
}
|
|
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;
|
|
18221
|
+
});
|
|
18222
|
+
}
|
|
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();
|
|
17950
18288
|
|
|
17951
|
-
export { World };
|
|
18289
|
+
export { Asset, DroppedAsset, User, Visitor, World };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 {};
|
package/dist/types/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./DroppedAssetTypes";
|
|
2
|
+
export * from "./VisitorTypes";
|
|
@@ -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
|
+
});
|