@rtsdk/topia 0.0.9 → 0.0.11

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Javascript RTSDK - Topia Client Library
2
+
3
+ The Topia Client Library leverages the Topia Public API and allows users to interact with the topia systems and modify their world programmatically.
4
+
5
+ ## Get Started
6
+
7
+ Run `yarn add @rtsdk/topia` or `npm install @rtsdk/topia`
8
+
9
+ ## Authorization
10
+
11
+ A Topia provided API Key should be included with every object initialization as a parameter named `apiKey`. This API Key is used to in authorization headers in all calls to the Public API.
12
+
13
+ ## Testing
14
+
15
+ We use Jest for testing and take advantage of dependency injection to pass mock data into our services.
16
+
17
+ To run the test suite, please run:
18
+
19
+ `yarn test`
@@ -39,6 +39,7 @@ export const worlds = [
39
39
  },
40
40
  tileBackgroundEverywhere: null,
41
41
  useTopiaPassword: false,
42
+ urlSlug: "magic",
42
43
  width: 4096,
43
44
  },
44
45
  {
@@ -1,50 +1,8 @@
1
1
  import { getErrorMessage, publicAPI } from "utils";
2
2
  export class Asset {
3
- addedOn;
4
- apiKey;
5
- assetName;
6
- creatorTags;
7
- id;
8
- isPublic;
9
- kitId;
10
- layer0;
11
- layer1;
12
- library;
13
- originalAssetId;
14
- originalKit;
15
- ownerId;
16
- ownerName;
17
- platformAsset;
18
- purchased;
19
- purchaseDate;
20
- purchasedFrom;
21
- specialType;
22
- transactionId;
23
- type;
24
- urlSlug;
25
- 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 = "") {
26
- this.addedOn = addedOn;
3
+ constructor({ apiKey, args }) {
27
4
  this.apiKey = apiKey;
28
- this.assetName = assetName;
29
- this.creatorTags = creatorTags;
30
- this.id = id;
31
- this.isPublic = isPublic;
32
- this.kitId = kitId;
33
- this.layer0 = layer0;
34
- this.layer1 = layer1;
35
- this.library = library;
36
- this.originalAssetId = originalAssetId;
37
- this.originalKit = originalKit;
38
- this.ownerId = ownerId;
39
- this.ownerName = ownerName;
40
- this.platformAsset = platformAsset;
41
- this.purchased = purchased;
42
- this.purchaseDate = purchaseDate;
43
- this.purchasedFrom = purchasedFrom;
44
- this.specialType = specialType;
45
- this.transactionId = transactionId;
46
- this.type = type;
47
- this.urlSlug = urlSlug;
5
+ Object.assign(this, args);
48
6
  }
49
7
  fetchAssetsByEmail(ownerEmail) {
50
8
  return new Promise((resolve, reject) => {
@@ -1,16 +1,32 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _DroppedAsset_updateDroppedAsset;
1
7
  import { getErrorMessage, publicAPI } from "utils";
2
8
  import Asset from "./Asset";
3
9
  export class DroppedAsset extends Asset {
4
- apiKey;
5
- text;
6
- urlSlug;
7
- // 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!)
8
- constructor(apiKey, args, text, urlSlug) {
9
- 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);
10
+ constructor({ apiKey, id, args, urlSlug, }) {
11
+ super({ apiKey, args });
12
+ // update dropped assets
13
+ _DroppedAsset_updateDroppedAsset.set(this, (payload, updateType) => {
14
+ return new Promise((resolve, reject) => {
15
+ publicAPI(this.apiKey)
16
+ .put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload))
17
+ .then(() => {
18
+ resolve("Success!");
19
+ })
20
+ .catch((error) => {
21
+ reject(new Error(getErrorMessage(error)));
22
+ });
23
+ });
24
+ });
25
+ Object.assign(this, args);
10
26
  this.apiKey = apiKey;
11
- this.text = text;
27
+ this.id = id;
28
+ this.text = args.text;
12
29
  this.urlSlug = urlSlug;
13
- Object.assign(this, args);
14
30
  this.updateCustomText;
15
31
  }
16
32
  // get dropped asset
@@ -40,25 +56,9 @@ export class DroppedAsset extends Asset {
40
56
  });
41
57
  });
42
58
  }
43
- // update dropped assets
44
- #updateDroppedAsset = (payload, updateType) => {
45
- console.log("apiKey", this.apiKey);
46
- return new Promise((resolve, reject) => {
47
- publicAPI(this.apiKey)
48
- .put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, {
49
- ...payload,
50
- })
51
- .then(() => {
52
- resolve("Success!");
53
- })
54
- .catch((error) => {
55
- reject(new Error(getErrorMessage(error)));
56
- });
57
- });
58
- };
59
59
  updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
60
60
  return new Promise((resolve, reject) => {
61
- return this.#updateDroppedAsset({ assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
61
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
62
62
  .then(resolve)
63
63
  .catch((error) => {
64
64
  reject(new Error(getErrorMessage(error)));
@@ -67,7 +67,7 @@ export class DroppedAsset extends Asset {
67
67
  }
68
68
  updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
69
69
  return new Promise((resolve, reject) => {
70
- return this.#updateDroppedAsset({ clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
70
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
71
71
  .then(resolve)
72
72
  .catch((error) => {
73
73
  reject(new Error(getErrorMessage(error)));
@@ -76,7 +76,7 @@ export class DroppedAsset extends Asset {
76
76
  }
77
77
  updateCustomText(style, text) {
78
78
  return new Promise((resolve, reject) => {
79
- return this.#updateDroppedAsset({ style, text }, "set-custom-text")
79
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { style, text }, "set-custom-text")
80
80
  .then(resolve)
81
81
  .catch((error) => {
82
82
  reject(new Error(getErrorMessage(error)));
@@ -85,7 +85,7 @@ export class DroppedAsset extends Asset {
85
85
  }
86
86
  updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
87
87
  return new Promise((resolve, reject) => {
88
- return this.#updateDroppedAsset({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
88
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
89
89
  .then(resolve)
90
90
  .catch((error) => {
91
91
  reject(new Error(getErrorMessage(error)));
@@ -94,7 +94,7 @@ export class DroppedAsset extends Asset {
94
94
  }
95
95
  updateMuteZone(isMutezone) {
96
96
  return new Promise((resolve, reject) => {
97
- return this.#updateDroppedAsset({ isMutezone }, "set-mute-zone")
97
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isMutezone }, "set-mute-zone")
98
98
  .then(resolve)
99
99
  .catch((error) => {
100
100
  reject(new Error(getErrorMessage(error)));
@@ -103,7 +103,7 @@ export class DroppedAsset extends Asset {
103
103
  }
104
104
  updatePosition(x, y) {
105
105
  return new Promise((resolve, reject) => {
106
- return this.#updateDroppedAsset({ x, y }, "set-position")
106
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { x, y }, "set-position")
107
107
  .then(resolve)
108
108
  .catch((error) => {
109
109
  reject(new Error(getErrorMessage(error)));
@@ -112,7 +112,7 @@ export class DroppedAsset extends Asset {
112
112
  }
113
113
  updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
114
114
  return new Promise((resolve, reject) => {
115
- return this.#updateDroppedAsset({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
115
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
116
116
  .then(resolve)
117
117
  .catch((error) => {
118
118
  reject(new Error(getErrorMessage(error)));
@@ -121,7 +121,7 @@ export class DroppedAsset extends Asset {
121
121
  }
122
122
  updateScale(assetScale) {
123
123
  return new Promise((resolve, reject) => {
124
- return this.#updateDroppedAsset({ assetScale }, "change-scale")
124
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetScale }, "change-scale")
125
125
  .then(resolve)
126
126
  .catch((error) => {
127
127
  reject(new Error(getErrorMessage(error)));
@@ -130,7 +130,7 @@ export class DroppedAsset extends Asset {
130
130
  }
131
131
  updateUploadedMediaSelected(mediaId) {
132
132
  return new Promise((resolve, reject) => {
133
- return this.#updateDroppedAsset({ mediaId }, "change-uploaded-media-selected")
133
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { mediaId }, "change-uploaded-media-selected")
134
134
  .then(resolve)
135
135
  .catch((error) => {
136
136
  reject(new Error(getErrorMessage(error)));
@@ -139,7 +139,7 @@ export class DroppedAsset extends Asset {
139
139
  }
140
140
  updateWebImageLayers(bottom, top) {
141
141
  return new Promise((resolve, reject) => {
142
- return this.#updateDroppedAsset({ bottom, top }, "set-webimage-layers")
142
+ return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { bottom, top }, "set-webimage-layers")
143
143
  .then(resolve)
144
144
  .catch((error) => {
145
145
  reject(new Error(getErrorMessage(error)));
@@ -147,4 +147,5 @@ export class DroppedAsset extends Asset {
147
147
  });
148
148
  }
149
149
  }
150
- export default Asset;
150
+ _DroppedAsset_updateDroppedAsset = new WeakMap();
151
+ export default DroppedAsset;
@@ -0,0 +1,91 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _User_worldsMap;
13
+ import { World } from "controllers/World";
14
+ import { getErrorMessage, publicAPI } from "utils";
15
+ /**
16
+ * Create an instance of User class with a given apiKey
17
+ *
18
+ * ```ts
19
+ * await new User({ apiKey: API_KEY, email: "example@email.io" })
20
+ * ```
21
+ */
22
+ export class User {
23
+ constructor({ apiKey, email }) {
24
+ _User_worldsMap.set(this, void 0);
25
+ __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
26
+ this.apiKey = apiKey;
27
+ this.email = email;
28
+ }
29
+ get worlds() {
30
+ return __classPrivateFieldGet(this, _User_worldsMap, "f");
31
+ }
32
+ /**
33
+ * @summary
34
+ * Returns all scenes owned by User when an email address is provided
35
+ */
36
+ fetchScenesByEmail() {
37
+ return new Promise((resolve, reject) => {
38
+ if (!this.email)
39
+ reject("There is no email associated with this user.");
40
+ publicAPI(this.apiKey)
41
+ .get(`/scenes/my-scenes?email=${this.email}`)
42
+ .then((response) => {
43
+ resolve(response.data);
44
+ })
45
+ .catch((error) => {
46
+ reject(new Error(getErrorMessage(error)));
47
+ });
48
+ });
49
+ }
50
+ /**
51
+ * @summary
52
+ * Retrieves all worlds owned by user with matching API Key,
53
+ * creates a new World object for each,
54
+ * and creates new map of Worlds accessible via user.worlds
55
+ *
56
+ * @usage
57
+ * ```ts
58
+ * await user.fetchWorldsByKey();
59
+ * const userWorlds = user.worlds;
60
+ * ```
61
+ *
62
+ * @result
63
+ * ```ts
64
+ * { urlSlug: new World({ apiKey, worldArgs, urlSlug }) }
65
+ * ```
66
+ */
67
+ fetchWorldsByKey() {
68
+ return new Promise((resolve, reject) => {
69
+ publicAPI(this.apiKey)
70
+ .get("/user/worlds")
71
+ .then((response) => {
72
+ const tempWorldsMap = {};
73
+ for (const i in response.data) {
74
+ const worldDetails = response.data[i];
75
+ tempWorldsMap[worldDetails.urlSlug] = new World({
76
+ apiKey: this.apiKey,
77
+ args: worldDetails,
78
+ urlSlug: worldDetails.urlSlug,
79
+ });
80
+ }
81
+ __classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
82
+ resolve("Success!");
83
+ })
84
+ .catch((error) => {
85
+ reject(new Error(getErrorMessage(error)));
86
+ });
87
+ });
88
+ }
89
+ }
90
+ _User_worldsMap = new WeakMap();
91
+ export default User;
@@ -1,50 +1,11 @@
1
1
  import { getErrorMessage, publicAPI } from "utils";
2
2
  export class Visitor {
3
- apiKey;
4
- color;
5
- displayName;
6
- gestureType;
7
- hidden;
8
- isAdmin;
9
- isBackground;
10
- isMobile;
11
- isRecording;
12
- isRecordingBot;
13
- lastUpdate;
14
- moveFrom;
15
- movedOn;
16
- moveTo;
17
- muted;
18
- performer;
19
- performerNear;
20
- playerId;
21
- shareScreen;
22
- sitting;
23
- urlSlug;
24
- username;
25
- 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) {
3
+ constructor({ apiKey, args, urlSlug }) {
4
+ Object.assign(this, args);
26
5
  this.apiKey = apiKey;
27
- this.color = color;
28
- this.displayName = displayName;
29
- this.gestureType = gestureType;
30
- this.hidden = hidden;
31
- this.isAdmin = isAdmin;
32
- this.isBackground = isBackground;
33
- this.isMobile = isMobile;
34
- this.isRecording = isRecording;
35
- this.isRecordingBot = isRecordingBot;
36
- this.lastUpdate = lastUpdate;
37
- this.moveFrom = moveFrom;
38
- this.movedOn = movedOn;
39
- this.moveTo = moveTo;
40
- this.muted = muted;
41
- this.performer = performer;
42
- this.performerNear = performerNear;
43
- this.playerId = playerId;
44
- this.shareScreen = shareScreen;
45
- this.sitting = sitting;
6
+ this.moveTo = args.moveTo;
7
+ this.playerId = args.playerId;
46
8
  this.urlSlug = urlSlug;
47
- this.username = username;
48
9
  this.moveVisitor;
49
10
  }
50
11
  moveVisitor(shouldTeleportVisitor, x, y) {
@@ -1,35 +1,42 @@
1
- import { createVisitor, getErrorMessage, publicAPI, scatterVisitors } from "utils";
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
+ if (kind === "m") throw new TypeError("Private method is not writable");
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
+ 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");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
+ 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");
19
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
+ var _World_droppedAssetsMap, _World_visitorsMap;
22
+ import { getErrorMessage, publicAPI, removeUndefined, scatterVisitors } from "utils";
2
23
  import { DroppedAsset } from "controllers/DroppedAsset";
3
24
  import { Visitor } from "controllers/Visitor";
4
25
  export class World {
5
- #droppedAssetsMap;
6
- #visitorsMap;
7
- apiKey;
8
- background;
9
- controls;
10
- created;
11
- description;
12
- enforceWhitelistOnLogin;
13
- forceAuthOnLogin;
14
- height;
15
- heroImage;
16
- mapExists;
17
- name;
18
- redirectTo;
19
- spawnPosition;
20
- tileBackgroundEverywhere;
21
- urlSlug;
22
- useTopiaPassword;
23
- width;
26
+ constructor({ apiKey, args, urlSlug }) {
27
+ _World_droppedAssetsMap.set(this, void 0);
28
+ _World_visitorsMap.set(this, void 0);
29
+ Object.assign(this, args);
30
+ __classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
31
+ __classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
32
+ this.apiKey = apiKey;
33
+ this.urlSlug = urlSlug;
34
+ }
24
35
  get droppedAssets() {
25
- return this.#droppedAssetsMap;
36
+ return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
26
37
  }
27
38
  get visitors() {
28
- return this.#visitorsMap;
29
- }
30
- constructor(apiKey, urlSlug) {
31
- this.apiKey = apiKey;
32
- this.urlSlug = urlSlug;
39
+ return __classPrivateFieldGet(this, _World_visitorsMap, "f");
33
40
  }
34
41
  // world details
35
42
  fetchDetails() {
@@ -45,11 +52,22 @@ export class World {
45
52
  });
46
53
  });
47
54
  }
48
- updateDetails() {
55
+ updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
56
+ const payload = {
57
+ controls,
58
+ description,
59
+ forceAuthOnLogin,
60
+ height,
61
+ name,
62
+ spawnPosition,
63
+ width,
64
+ };
49
65
  return new Promise((resolve, reject) => {
50
66
  publicAPI(this.apiKey)
51
- .get(`/world/${this.urlSlug}/world-details`)
67
+ .put(`/world/${this.urlSlug}/world-details`, payload)
52
68
  .then(() => {
69
+ const cleanPayload = removeUndefined(payload);
70
+ Object.assign(this, cleanPayload);
53
71
  resolve("Success!");
54
72
  })
55
73
  .catch((error) => {
@@ -66,9 +84,13 @@ export class World {
66
84
  // create temp map and then update private property only once
67
85
  const tempVisitorsMap = {};
68
86
  for (const playerId in response.data) {
69
- tempVisitorsMap[playerId] = createVisitor(Visitor, this.apiKey, response.data[playerId], this.urlSlug);
87
+ tempVisitorsMap[playerId] = new Visitor({
88
+ apiKey: this.apiKey,
89
+ args: response.data[playerId],
90
+ urlSlug: this.urlSlug,
91
+ });
70
92
  }
71
- this.#visitorsMap = tempVisitorsMap;
93
+ __classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
72
94
  resolve("Success!");
73
95
  })
74
96
  .catch((error) => {
@@ -76,33 +98,39 @@ export class World {
76
98
  });
77
99
  });
78
100
  }
79
- async currentVisitors() {
80
- try {
81
- await this.fetchVisitors();
82
- return this.visitors;
83
- }
84
- catch (error) {
85
- return error;
86
- }
101
+ currentVisitors() {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ try {
104
+ yield this.fetchVisitors();
105
+ return this.visitors;
106
+ }
107
+ catch (error) {
108
+ return error;
109
+ }
110
+ });
87
111
  }
88
- async moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
89
- if (shouldFetchVisitors)
90
- await this.fetchVisitors();
91
- const allPromises = [];
92
- if (!this.visitors)
93
- return;
94
- const objectKeys = Object.keys(this.visitors);
95
- objectKeys.forEach((key) => allPromises.push(this.#visitorsMap[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
96
- const outcomes = await Promise.allSettled(allPromises);
97
- return outcomes;
112
+ moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ if (shouldFetchVisitors)
115
+ yield this.fetchVisitors();
116
+ const allPromises = [];
117
+ if (!this.visitors)
118
+ return;
119
+ const objectKeys = Object.keys(this.visitors);
120
+ objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
121
+ const outcomes = yield Promise.allSettled(allPromises);
122
+ return outcomes;
123
+ });
98
124
  }
99
- async moveVisitors(visitorsToMove) {
100
- const allPromises = [];
101
- visitorsToMove.forEach((v) => {
102
- allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
125
+ moveVisitors(visitorsToMove) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ const allPromises = [];
128
+ visitorsToMove.forEach((v) => {
129
+ allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
130
+ });
131
+ const outcomes = yield Promise.allSettled(allPromises);
132
+ return outcomes;
103
133
  });
104
- const outcomes = await Promise.allSettled(allPromises);
105
- return outcomes;
106
134
  }
107
135
  // dropped assets
108
136
  fetchDroppedAssets() {
@@ -114,9 +142,14 @@ export class World {
114
142
  const tempDroppedAssetsMap = {};
115
143
  for (const id in response.data) {
116
144
  // tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
117
- tempDroppedAssetsMap[id] = new DroppedAsset(this.apiKey, response.data[id], "", this.urlSlug);
145
+ tempDroppedAssetsMap[id] = new DroppedAsset({
146
+ apiKey: this.apiKey,
147
+ id,
148
+ args: response.data[id],
149
+ urlSlug: this.urlSlug,
150
+ });
118
151
  }
119
- this.#droppedAssetsMap = tempDroppedAssetsMap;
152
+ __classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
120
153
  resolve("Success!");
121
154
  })
122
155
  .catch((error) => {
@@ -124,14 +157,30 @@ export class World {
124
157
  });
125
158
  });
126
159
  }
127
- async updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
128
- // adds ability to update any styles for specified dropped assets only while preserving text
129
- const allPromises = [];
130
- droppedAssetsToUpdate.forEach((a) => {
131
- allPromises.push(a.updateCustomText(style, a.text));
160
+ updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ // adds ability to update any styles for specified dropped assets only while preserving text
163
+ const allPromises = [];
164
+ droppedAssetsToUpdate.forEach((a) => {
165
+ allPromises.push(a.updateCustomText(style, a.text));
166
+ });
167
+ const outcomes = yield Promise.allSettled(allPromises);
168
+ return outcomes;
169
+ });
170
+ }
171
+ // scenes
172
+ replaceScene(sceneId) {
173
+ return new Promise((resolve, reject) => {
174
+ publicAPI(this.apiKey)
175
+ .put(`/world/${this.urlSlug}/change-scene`, { sceneId })
176
+ .then(() => {
177
+ resolve("Success!");
178
+ })
179
+ .catch((error) => {
180
+ reject(new Error(getErrorMessage(error)));
181
+ });
132
182
  });
133
- const outcomes = await Promise.allSettled(allPromises);
134
- return outcomes;
135
183
  }
136
184
  }
185
+ _World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
137
186
  export default World;
@@ -1,14 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { assets } from "../../__mocks__";
2
11
  import { Asset } from "..";
3
12
  afterEach(() => {
4
13
  jest.resetAllMocks();
5
14
  });
6
15
  describe("Asset Class", () => {
7
- it("should return an array of assets owned by specific email address", async () => {
8
- const testAsset = new Asset("", "key");
16
+ it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const testAsset = new Asset({ apiKey: "key", args: { id: "abc123" } });
9
18
  testAsset.fetchAssetsByEmail = jest.fn().mockReturnValue(assets);
10
- const mockAssets = await testAsset.fetchAssetsByEmail("lina@topia.io");
19
+ const mockAssets = yield testAsset.fetchAssetsByEmail("lina@topia.io");
11
20
  expect(testAsset.fetchAssetsByEmail).toHaveBeenCalled();
12
21
  expect(mockAssets).toBeDefined();
13
- });
22
+ }));
14
23
  });